1
2
3
4
5 package p
6
7
8
9 var _ any
10 func _[_ any, _ interface{any}](any) {
11 var _ any
12 }
13
14 func identity[T any](x T) T { return x }
15
16 func _[_ any](x int) int { panic(0) }
17 func _[T any](T T)() {}
18 func _[T, T any]() {}
19
20
21 func _[_ (any)]() {}
22 func _[_ (interface{})]() {}
23
24 func reverse[T any](list []T) []T {
25 rlist := make([]T, len(list))
26 i := len(list)
27 for _, x := range list {
28 i--
29 rlist[i] = x
30 }
31 return rlist
32 }
33
34 var _ = reverse
35 var _ = reverse[int, float32 ] ([]int{1, 2, 3})
36 var _ = reverse[int]([ ]float32{1, 2, 3})
37 var f = reverse[chan int]
38 var _ = f(0 )
39
40 func swap[A, B any](a A, b B) (B, A) { return b, a }
41
42 var _ = swap [int, float32](1, 2)
43 var f32, i = swap[int, float32](swap[float32, int](1, 2))
44 var _ float32 = f32
45 var _ int = i
46
47 func swapswap[A, B any](a A, b B) (A, B) {
48 return swap[B, A](b, a)
49 }
50
51 type F[A, B any] func(A, B) (B, A)
52
53 func min[T interface{ ~int }](x, y T) T {
54 if x < y {
55 return x
56 }
57 return y
58 }
59
60 func _[T interface{~int | ~float32}](x, y T) bool { return x < y }
61 func _[T any](x, y T) bool { return x < y }
62 func _[T interface{~int | ~float32 | ~bool}](x, y T) bool { return x < y }
63
64 func _[T C1[T]](x, y T) bool { return x < y }
65 func _[T C2[T]](x, y T) bool { return x < y }
66
67 type C1[T any] interface{}
68 type C2[T any] interface{ ~int | ~float32 }
69
70 func new[T any]() *T {
71 var x T
72 return &x
73 }
74
75 var _ = new
76 var _ *int = new[int]()
77
78 func _[T any](map[T ]int) {}
79
80 func f1[T1 any](struct{T1 }) int { panic(0) }
81 var _ = f1[int](struct{T1}{})
82 type T1 = int
83
84 func f2[t1 any](struct{t1 ; x float32}) int { panic(0) }
85 var _ = f2[t1](struct{t1; x float32}{})
86 type t1 = int
87
88
89 func f3[A, B, C any](A, struct{x B}, func(A, struct{x B}, *C)) int { panic(0) }
90
91 var _ = f3[int, rune, bool](1, struct{x rune}{}, nil)
92
93
94
95 func _[T any] (x T, i int) { _ = x [i] }
96 func _[T interface{ ~int }] (x T, i int) { _ = x [i] }
97 func _[T interface{ ~string }] (x T, i int) { _ = x[i] }
98 func _[T interface{ ~[]int }] (x T, i int) { _ = x[i] }
99 func _[T interface{ ~[10]int | ~*[20]int | ~map[int]int }] (x T, i int) { _ = x [i] }
100 func _[T interface{ ~string | ~[]byte }] (x T, i int) { _ = x[i] }
101 func _[T interface{ ~[]int | ~[1]rune }] (x T, i int) { _ = x [i] }
102 func _[T interface{ ~string | ~[]rune }] (x T, i int) { _ = x [i] }
103
104
105 func _[T interface{ ~[]E | ~map[int]E }, E any](x T, i int) { _ = x [i] }
106 func _[T interface{ ~[]E }, E any](x T, i int) { _ = &x[i] }
107 func _[T interface{ ~map[int]E }, E any](x T, i int) { _, _ = x[i] }
108 func _[T interface{ ~map[int]E }, E any](x T, i int) { _ = &x [i] }
109 func _[T interface{ ~map[int]E | ~map[uint]E }, E any](x T, i int) { _ = x [i] }
110 func _[T interface{ ~[]E | ~map[string]E }, E any](x T, i int) { _ = x [i] }
111
112
113 func _[T interface{ [10]int }](x T, i int) { _ = x[i]; _ = x[9]; _ = x[10 ] }
114 func _[T interface{ [10]byte | string }](x T, i int) { _ = x[i]; _ = x[9]; _ = x[10 ] }
115 func _[T interface{ [10]int | *[20]int | []int }](x T, i int) { _ = x[i]; _ = x[9]; _ = x[10 ] }
116
117
118 func _[T string](x T) { _ = x[0]; x [0] = 0 }
119 func _[T []byte | string](x T) { x [0] = 0 }
120 func _[T [10]byte]() { f := func() (x T) { return }; f ()[0] = 0 }
121 func _[T [10]byte]() { f := func() (x *T) { return }; f ()[0] = 0 }
122 func _[T [10]byte]() { f := func() (x *T) { return }; (*f())[0] = 0 }
123 func _[T *[10]byte]() { f := func() (x T) { return }; f()[0] = 0 }
124
125
126
127 func _[T interface{ ~[10]E }, E any] (x T, i, j, k int) { var _ []E = x[i:j] }
128 func _[T interface{ ~[10]E }, E any] (x T, i, j, k int) { var _ []E = x[i:j:k] }
129 func _[T interface{ ~[]byte }] (x T, i, j, k int) { var _ T = x[i:j] }
130 func _[T interface{ ~[]byte }] (x T, i, j, k int) { var _ T = x[i:j:k] }
131 func _[T interface{ ~string }] (x T, i, j, k int) { var _ T = x[i:j] }
132 func _[T interface{ ~string }] (x T, i, j, k int) { var _ T = x[i:j:k ] }
133
134 type myByte1 []byte
135 type myByte2 []byte
136 func _[T interface{ []byte | myByte1 | myByte2 }] (x T, i, j, k int) { var _ T = x[i:j:k] }
137 func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x [i:j:k] }
138
139 func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j] }
140 func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j:k ] }
141 func _[T interface{ []byte | myByte1 | []int | string }] (x T, i, j, k int) { var _ T = x [i:j] }
142
143
144
145 func _[T any](x T) { _ = len(x ) }
146 func _[T interface{ ~int }](x T) { _ = len(x ) }
147 func _[T interface{ ~string | ~[]byte | ~int }](x T) { _ = len(x ) }
148 func _[T interface{ ~string }](x T) { _ = len(x) }
149 func _[T interface{ ~[10]int }](x T) { _ = len(x) }
150 func _[T interface{ ~[]byte }](x T) { _ = len(x) }
151 func _[T interface{ ~map[int]int }](x T) { _ = len(x) }
152 func _[T interface{ ~chan int }](x T) { _ = len(x) }
153 func _[T interface{ ~string | ~[]byte | ~chan int }](x T) { _ = len(x) }
154
155 func _[T any](x T) { _ = cap(x ) }
156 func _[T interface{ ~int }](x T) { _ = cap(x ) }
157 func _[T interface{ ~string | ~[]byte | ~int }](x T) { _ = cap(x ) }
158 func _[T interface{ ~string }](x T) { _ = cap(x ) }
159 func _[T interface{ ~[10]int }](x T) { _ = cap(x) }
160 func _[T interface{ ~[]byte }](x T) { _ = cap(x) }
161 func _[T interface{ ~map[int]int }](x T) { _ = cap(x ) }
162 func _[T interface{ ~chan int }](x T) { _ = cap(x) }
163 func _[T interface{ ~[]byte | ~chan int }](x T) { _ = cap(x) }
164
165
166
167 func _[T interface{}](x T) {
168 for range x {}
169 }
170
171 type myString string
172
173 func _[
174 B1 interface{ string },
175 B2 interface{ string | myString },
176
177 C1 interface{ chan int },
178 C2 interface{ chan int | <-chan int },
179 C3 interface{ chan<- int },
180
181 S1 interface{ []int },
182 S2 interface{ []int | [10]int },
183
184 A1 interface{ [10]int },
185 A2 interface{ [10]int | []int },
186
187 P1 interface{ *[10]int },
188 P2 interface{ *[10]int | *[]int },
189
190 M1 interface{ map[string]int },
191 M2 interface{ map[string]int | map[string]string },
192 ]() {
193 var b0 string
194 for range b0 {}
195 for _ = range b0 {}
196 for _, _ = range b0 {}
197
198 var b1 B1
199 for range b1 {}
200 for _ = range b1 {}
201 for _, _ = range b1 {}
202
203 var b2 B2
204 for range b2 {}
205
206 var c0 chan int
207 for range c0 {}
208 for _ = range c0 {}
209 for _, _ = range c0 {}
210
211 var c1 C1
212 for range c1 {}
213 for _ = range c1 {}
214 for _, _ = range c1 {}
215
216 var c2 C2
217 for range c2 {}
218
219 var c3 C3
220 for range c3 {}
221
222 var s0 []int
223 for range s0 {}
224 for _ = range s0 {}
225 for _, _ = range s0 {}
226
227 var s1 S1
228 for range s1 {}
229 for _ = range s1 {}
230 for _, _ = range s1 {}
231
232 var s2 S2
233 for range s2 {}
234
235 var a0 []int
236 for range a0 {}
237 for _ = range a0 {}
238 for _, _ = range a0 {}
239
240 var a1 A1
241 for range a1 {}
242 for _ = range a1 {}
243 for _, _ = range a1 {}
244
245 var a2 A2
246 for range a2 {}
247
248 var p0 *[10]int
249 for range p0 {}
250 for _ = range p0 {}
251 for _, _ = range p0 {}
252
253 var p1 P1
254 for range p1 {}
255 for _ = range p1 {}
256 for _, _ = range p1 {}
257
258 var p2 P2
259 for range p2 {}
260
261 var m0 map[string]int
262 for range m0 {}
263 for _ = range m0 {}
264 for _, _ = range m0 {}
265
266 var m1 M1
267 for range m1 {}
268 for _ = range m1 {}
269 for _, _ = range m1 {}
270
271 var m2 M2
272 for range m2 {}
273 }
274
275
276
277 var _ = new ()
278
279 func f4[A, B, C any](A, B) C { panic(0) }
280
281 var _ = f4 (1, 2)
282 var _ = f4[int, float32, complex128](1, 2)
283
284 func f5[A, B, C any](A, []*B, struct{f []C}) int { panic(0) }
285
286 var _ = f5[int, float32, complex128](0, nil, struct{f []complex128}{})
287 var _ = f5 (0, nil, struct{f []complex128}{})
288 var _ = f5(0, []*float32{new[float32]()}, struct{f []complex128}{})
289
290 func f6[A any](A, []A) int { panic(0) }
291
292 var _ = f6(0, nil)
293
294 func f6nil[A any](A) int { panic(0) }
295
296 var _ = f6nil (nil)
297
298
299
300 func f7[T any](...T) T { panic(0) }
301
302 var _ int = f7 ()
303 var _ int = f7(1)
304 var _ int = f7(1, 2)
305 var _ int = f7([]int{}...)
306 var _ int = f7 ([]float64{}...)
307 var _ float64 = f7([]float64{}...)
308 var _ = f7[float64](1, 2.3)
309 var _ = f7(float64(1), 2.3)
310 var _ = f7(1, 2.3)
311 var _ = f7(1.2, 3)
312
313 func f8[A, B any](A, B, ...B) int { panic(0) }
314
315 var _ = f8(1)
316 var _ = f8(1, 2.3)
317 var _ = f8(1, 2.3, 3.4, 4.5)
318 var _ = f8(1, 2.3, 3.4, 4)
319 var _ = f8[int, float64](1, 2.3, 3.4, 4)
320
321 var _ = f8[int, float64](0, 0, nil...)
322
323
324
325 func init() {}
326 func init[_ any]() {}
327 func init[P any]() {}
328
329 type T struct {}
330
331 func (T) m1() {}
332 func (T) m2[ _ any]() {}
333 func (T) m3[ P any]() {}
334
335
336
337 type S1[P any] struct { f P }
338
339 func f9[P any](x S1[P]) {}
340
341 func _() {
342 f9[int](S1[int]{42})
343 f9(S1[int]{42})
344 }
345
346 type S2[A, B, C any] struct{}
347
348 func f10[X, Y, Z any](a S2[X, int, Z], b S2[X, Y, bool]) {}
349
350 func _[P any]() {
351 f10[int, float32, string](S2[int, int, string]{}, S2[int, float32, bool]{})
352 f10(S2[int, int, string]{}, S2[int, float32, bool]{})
353 f10(S2[P, int, P]{}, S2[P, float32, bool]{})
354 }
355
356
357
358
359 func f11[T any]() {}
360
361 func _() {
362 f11[int]()
363 }
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380 func (_ S1[P]) m()
381
382 func _() {
383 m := S1[int].m
384 m(struct { f int }{42})
385 }
386
387 func _[T any] (x T) {
388 m := S1[T].m
389 m(S1[T]{x})
390 }
391
392 type I1[A any] interface {
393 m1(A)
394 }
395
396 var _ I1[int] = r1[int]{}
397
398 type r1[T any] struct{}
399
400 func (_ r1[T]) m1(T)
401
402 type I2[A, B any] interface {
403 m1(A)
404 m2(A) B
405 }
406
407 var _ I2[int, float32] = R2[int, float32]{}
408
409 type R2[P, Q any] struct{}
410
411 func (_ R2[X, Y]) m1(X)
412 func (_ R2[X, Y]) m2(X) Y
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465 func _[T any](x T) {
466 _ = x .(int)
467 switch x .(type) {
468 }
469
470
471 var t interface{} = x
472 _ = t.(int)
473 switch t.(type) {
474 }
475 }
476
477 func _[T interface{~int}](x T) {
478 _ = x .(int)
479 switch x .(type) {
480 }
481
482
483 var t interface{} = x
484 _ = t.(int)
485 switch t.(type) {
486 }
487 }
488
489
490 type C[P any] interface{}
491
492 func _[P C[P]] (x P) {
493 x.m ()
494 }
495
496 type I interface {}
497
498 func _[P I] (x P) {
499 x.m ()
500 }
501
502 func _[P interface{}] (x P) {
503 x.m ()
504 }
505
506 func _[P any] (x P) {
507 x.m ()
508 }
509
View as plain text