1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package generics
6
7 func _[A, B any](a A, b B) int {}
8 func _[T any](x, y T) T
9
10 type T[P any] struct{}
11 type T[P1, P2, P3 any] struct{}
12
13 type T[P C] struct{}
14 type T[P1, P2, P3 C] struct{}
15
16 type T[P C[P]] struct{}
17 type T[P1, P2, P3 C[P1, P2, P3]] struct{}
18
19 func f[P any](x P)
20 func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{}
21
22 func f[P interface{}](x P)
23 func f[P1, P2, P3 interface{ m1(P1); ~P2|~P3 }](x1 P1, x2 P2, x3 P3) struct{}
24 func f[P any](T1[P], T2[P]) T3[P]
25
26 func (x T[P]) m()
27 func ((T[P])) m(x T[P]) P
28
29 func _() {
30 type _ []T[P]
31 var _ []T[P]
32 _ = []T[P]{}
33 }
34
35 // type constraint literals with elided interfaces
36 func _[P ~int, Q int | string]() {}
37 func _[P struct{f int}, Q *P]() {}
38
39 // various potentially ambiguous type parameter lists (issue #49482)
40 type _[P *T,] struct{}
41 type _[P *T, _ any] struct{}
42 type _[P (*T),] struct{}
43 type _[P (*T), _ any] struct{}
44 type _[P (T),] struct{}
45 type _[P (T), _ any] struct{}
46
47 type _[P *struct{}] struct{}
48 type _[P (*struct{})] struct{}
49 type _[P ([]int)] struct{}
50
51 // array type declarations
52 type _ [P(T)]struct{}
53 type _ [P((T))]struct{}
54 type _ [P * *T]struct{}
55 type _ [P * T]struct{}
56 type _ [P(*T)]struct{}
57 type _ [P(**T)]struct{}
58 type _ [P * T]struct{}
59 type _ [P * T - T]struct{}
60
61 type _[
62 P *T,
63 ] struct{}
64
65 // equivalent test cases for potentially ambiguous type parameter lists, except
66 // for function declarations there is no ambiguity (issue #51548)
67 func _[P *T,]() {}
68 func _[P *T, _ any]() {}
69 func _[P (*T),]() {}
70 func _[P (*T), _ any]() {}
71 func _[P (T),]() {}
72 func _[P (T), _ any]() {}
73
74 func _[P *struct{}] () {}
75 func _[P (*struct{})] () {}
76 func _[P ([]int)] () {}
77
78 func _ [P(T)]() {}
79 func _ [P((T))]() {}
80 func _ [P * *T]() {}
81 func _ [P * T]() {}
82 func _ [P(*T)]() {}
83 func _ [P(**T)]() {}
84 func _ [P * T]() {}
85
86 func _[
87 P *T,
88 ]() {}
89
View as plain text