Source file
test/typeparam/issue48225.go
1
2
3
4
5
6
7 package main
8
9 import "reflect"
10
11 type Foo[T any] struct {
12 val int
13 }
14
15 func (foo Foo[T]) Get() *T {
16 if foo.val != 1 {
17 panic("bad val field in Foo receiver")
18 }
19 return new(T)
20 }
21
22 var (
23 newInt = Foo[int]{val: 1}.Get
24 newString = Foo[string]{val: 1}.Get
25 )
26
27 func main() {
28 i := newInt()
29 s := newString()
30
31 if t := reflect.TypeOf(i).String(); t != "*int" {
32 panic(t)
33 }
34 if t := reflect.TypeOf(s).String(); t != "*string" {
35 panic(t)
36 }
37 }
38
View as plain text