1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 package main
40
41 import (
42 "fmt"
43 "reflect"
44 )
45
46 type test struct {
47 TArgs [2]reflect.Type
48 Instance reflect.Type
49 }
50
51 var tests []test
52
53 type intish interface{ ~int }
54
55 type Int int
56 type GlobalInt = Int
57
58 func F[A intish]() {
59 add := func(B, T interface{}) {
60 tests = append(tests, test{
61 TArgs: [2]reflect.Type{
62 reflect.TypeOf(A(0)),
63 reflect.TypeOf(B),
64 },
65 Instance: reflect.TypeOf(T),
66 })
67 }
68
69 type Int int
70
71 type T[B intish] struct{}
72
73 add(int(0), T[int]{})
74 add(Int(0), T[Int]{})
75 add(GlobalInt(0), T[GlobalInt]{})
76 add(A(0), T[A]{})
77
78 type U[_ any] int
79 type V U[int]
80 type W V
81
82 add(U[int](0), T[U[int]]{})
83 add(U[Int](0), T[U[Int]]{})
84 add(U[GlobalInt](0), T[U[GlobalInt]]{})
85 add(U[A](0), T[U[A]]{})
86 add(V(0), T[V]{})
87 add(W(0), T[W]{})
88 }
89
90 func main() {
91 type Int int
92
93 F[int]()
94 F[Int]()
95 F[GlobalInt]()
96
97 type U[_ any] int
98 type V U[int]
99 type W V
100
101 F[U[int]]()
102 F[U[Int]]()
103 F[U[GlobalInt]]()
104 F[V]()
105 F[W]()
106
107 type X[A any] U[X[A]]
108
109 F[X[int]]()
110 F[X[Int]]()
111 F[X[GlobalInt]]()
112
113 for j, tj := range tests {
114 for i, ti := range tests[:j+1] {
115 if (ti.TArgs == tj.TArgs) != (ti.Instance == tj.Instance) {
116 fmt.Printf("FAIL: %d,%d: %s, but %s\n", i, j, eq(ti.TArgs, tj.TArgs), eq(ti.Instance, tj.Instance))
117 }
118
119
120
121 if i != j && ti.Instance == tj.Instance {
122 fmt.Printf("%d,%d: %v\n", i, j, ti.Instance)
123 }
124 }
125 }
126 }
127
128 func eq(a, b interface{}) string {
129 op := "=="
130 if a != b {
131 op = "!="
132 }
133 return fmt.Sprintf("%v %s %v", a, op, b)
134 }
135
View as plain text