| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2022 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Test that type substitution works correctly even for a method of a generic type |
| 8 |
// that has multiple blank type params. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
import ( |
| 13 |
"fmt" |
| 14 |
) |
| 15 |
|
| 16 |
func main() { |
| 17 |
foo := &Foo[string, int]{ |
| 18 |
valueA: "i am a string", |
| 19 |
valueB: 123, |
| 20 |
} |
| 21 |
if got, want := fmt.Sprintln(foo), "i am a string 123\n"; got != want { |
| 22 |
panic(fmt.Sprintf("got %s, want %s", got, want)) |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
type Foo[T1 any, T2 any] struct { |
| 27 |
valueA T1 |
| 28 |
valueB T2 |
| 29 |
} |
| 30 |
|
| 31 |
func (f *Foo[_, _]) String() string { |
| 32 |
return fmt.Sprintf("%v %v", f.valueA, f.valueB) |
| 33 |
} |