1
2
3
4
5 package p
6
7 type List[E any] []E
8 var _ List[List[List[int]]]
9 var _ List[List[List[int]]] = []List[List[int]]{}
10
11 type (
12 T1[P1 any] struct {
13 f1 T2[P1, float32]
14 }
15
16 T2[P2, P3 any] struct {
17 f2 P2
18 f3 P3
19 }
20 )
21
22 func _() {
23 var x1 T1[int]
24 var x2 T2[int, float32]
25
26 x1.f1.f2 = 0
27 x1.f1 = x2
28 }
29
30 type T3[P any] T1[T2[P, P]]
31
32 func _() {
33 var x1 T3[int]
34 var x2 T2[int, int]
35 x1.f1.f2 = x2
36 }
37
38 func f[P any] (x P) List[P] {
39 return List[P]{x}
40 }
41
42 var (
43 _ []int = f(0)
44 _ []float32 = f[float32](10)
45 _ List[complex128] = f(1i)
46 _ []List[int] = f(List[int]{})
47 _ List[List[int]] = []List[int]{}
48 _ = []List[int]{}
49 )
50
51
52
53 func (l List[E]) Head() (_ E, _ bool) {
54 if len(l) > 0 {
55 return l[0], true
56 }
57 return
58 }
59
60
61
62 type Pair[K any] struct {
63 key K
64 }
65
66 type Receiver[T any] struct {
67 values T
68 }
69
70 type Iterator[K any] struct {
71 r Receiver[Pair[K]]
72 }
73
74 func Values [T any] (r Receiver[T]) T {
75 return r.values
76 }
77
78 func (it Iterator[K]) Next() K {
79 return Values[Pair[K]](it.r).key
80 }
81
82
83
84 type NumericAbs[T any] interface {
85 Abs() T
86 }
87
88 func AbsDifference[T NumericAbs[T]](x T) { panic(0) }
89
90
91
92
93
94
95
96
97
98
99
100
101 func g[P interface{ m() P }](x P) { panic(0) }
102
103
104
105
106
107
108
109
110
111
112
113
114 type T5[_ interface { a() }, _ interface{}] struct{}
115
116 type A[P any] struct{ x P }
117
118 func (_ A[P]) a() {}
119
120 var _ T5[A[int], int]
121
122
123
124
125
126
127
128
129
130
131 type R1[A any] struct{}
132 func (_ R1[A]) vm()
133 func (_ *R1[A]) pm()
134
135 func _[T any](r R1[T], p *R1[T]) {
136 r.vm()
137 r.pm()
138 p.vm()
139 p.pm()
140 }
141
142 type R2[A, B any] struct{}
143 func (_ R2[A, B]) vm()
144 func (_ *R2[A, B]) pm()
145
146 func _[T any](r R2[T, int], p *R2[string, T]) {
147 r.vm()
148 r.pm()
149 p.vm()
150 p.pm()
151 }
152
153
154 type _ interface {
155 m0()
156 ~int | ~string | ~bool
157 ~float32 | ~float64
158 m1()
159 m2()
160 ~complex64 | ~complex128
161 ~rune
162 }
163
164
165 type _ interface {
166 ~int|~ int
167 ~int|int
168 int|int
169 }
170
171 type _ interface {
172 ~struct{f int} | ~struct{g int} | ~ struct{f int}
173 }
174
175
176
177
178
179 type MyInt int
180 func add1[T interface{MyInt}](x T) T {
181 return x + 1
182 }
183
184 type MyString string
185 func double[T interface{MyInt|MyString}](x T) T {
186 return x + x
187 }
188
189
190
191
192
193 type E0 interface {
194 ~int | ~bool | ~string
195 }
196
197 type E1 interface {
198 ~int | ~float64 | ~string
199 }
200
201 type E2 interface {
202 ~float64
203 }
204
205 type I0 interface {
206 E0
207 }
208
209 func f0[T I0]() {}
210 var _ = f0[int]
211 var _ = f0[bool]
212 var _ = f0[string]
213 var _ = f0[float64 ]
214
215 type I01 interface {
216 E0
217 E1
218 }
219
220 func f01[T I01]() {}
221 var _ = f01[int]
222 var _ = f01[bool ]
223 var _ = f01[string]
224 var _ = f01[float64 ]
225
226 type I012 interface {
227 E0
228 E1
229 E2
230 }
231
232 func f012[T I012]() {}
233 var _ = f012[int ]
234 var _ = f012[bool ]
235 var _ = f012[string ]
236 var _ = f012[float64 ]
237
238 type I12 interface {
239 E1
240 E2
241 }
242
243 func f12[T I12]() {}
244 var _ = f12[int ]
245 var _ = f12[bool ]
246 var _ = f12[string ]
247 var _ = f12[float64]
248
249 type I0_ interface {
250 E0
251 ~int
252 }
253
254 func f0_[T I0_]() {}
255 var _ = f0_[int]
256 var _ = f0_[bool ]
257 var _ = f0_[string ]
258 var _ = f0_[float64 ]
259
260
261 var _ f0
262 var _ f0 [int]
263
264
265 type none interface {
266
267 int
268 string
269 }
270
271 func ff[T none]() {}
272 func gg[T any]() {}
273 func hh[T ~int]() {}
274
275 func _[T none]() {
276 _ = ff[int ]
277 _ = ff[T]
278 _ = gg[int]
279 _ = gg[T]
280 _ = hh[int]
281 _ = hh[T]
282 }
283
View as plain text