...
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
5package generics
6
7func _[A, B any](a A, b B) int {}
8func _[T any](x, y T) T
9
10type T[P any] struct{}
11type T[P1, P2, P3 any] struct{}
12
13type T[P C] struct{}
14type T[P1, P2, P3 C] struct{}
15
16type T[P C[P]] struct{}
17type T[P1, P2, P3 C[P1, P2, P3]] struct{}
18
19func f[P any](x P)
20func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{}
21
22func f[P interface{}](x P)
23func f[P1, P2, P3 interface {
24 m1(P1)
25 ~P2 | ~P3
26}](x1 P1, x2 P2, x3 P3) struct{}
27func f[P any](T1[P], T2[P]) T3[P]
28
29func (x T[P]) m()
30func (T[P]) m(x T[P]) P
31
32func _() {
33 type _ []T[P]
34 var _ []T[P]
35 _ = []T[P]{}
36}
37
38// type constraint literals with elided interfaces
39func _[P ~int, Q int | string]() {}
40func _[P struct{ f int }, Q *P]() {}
41
42// various potentially ambiguous type parameter lists (issue #49482)
43type _[P *T,] struct{}
44type _[P T | T] struct{}
45type _[P T | T | T | T] struct{}
46type _[P *T, _ any] struct{}
47type _[P *T,] struct{}
48type _[P *T,] struct{}
49type _[P ~int] struct{}
50type _[P *T, _ any] struct{}
51type _[P T] struct{}
52type _[P T, _ any] struct{}
53
54type _[P *struct{}] struct{}
55type _ [P(*struct{})]struct{}
56type _[P []int] struct{}
57
58// a type literal in an |-expression indicates a type parameter list (blank after type parameter list and type)
59type _[P *[]int] struct{}
60type _[P *T | T, Q T] struct{}
61type _[P *[]T | T] struct{}
62type _[P *T | T | T | T | ~T] struct{}
63type _[P *T | T | T | ~T | T] struct{}
64type _[P *T | T | struct{} | T] struct{}
65type _[P <-chan int] struct{}
66type _[P *T | struct{} | T] struct{}
67
68// a trailing comma always indicates a (possibly invalid) type parameter list (blank after type parameter list and type)
69type _[P *T,] struct{}
70type _[P *T | T,] struct{}
71type _[P *T | <-T | T,] struct{}
72
73// slice/array type declarations (no blank between array length and element type)
74type _ []byte
75type _ [n]byte
76type _ [P(T)]byte
77type _ [P((T))]byte
78type _ [P * *T]byte
79type _ [P * T]byte
80type _ [P(*T)]byte
81type _ [P(**T)]byte
82type _ [P*T - T]byte
83type _ [P*T - T]byte
84type _ [P*T | T]byte
85type _ [P*T | <-T | T]byte
86
87// equivalent test cases for potentially ambiguous type parameter lists, except
88// for function declarations there is no ambiguity (issue #51548)
89func _[P *T]() {}
90func _[P *T, _ any]() {}
91func _[P *T]() {}
92func _[P *T, _ any]() {}
93func _[P T]() {}
94func _[P T, _ any]() {}
95
96func _[P *struct{}]() {}
97func _[P *struct{}]() {}
98func _[P []int]() {}
99
100func _[P T]() {}
101func _[P T]() {}
102func _[P **T]() {}
103func _[P *T]() {}
104func _[P *T]() {}
105func _[P **T]() {}
106func _[P *T]() {}
107
108func _[
109 P *T,
110]() {
111}
View as plain text