1 // Copyright 2021 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 // This file contains test cases for typeset-only constraint elements.
6
7 package p
8
9 type (
10 _[_ t] t
11 _[_ ~t] t
12 _[_ t|t] t
13 _[_ ~t|t] t
14 _[_ t|~t] t
15 _[_ ~t|~t] t
16
17 _[_ t, _, _ t|t] t
18 _[_ t, _, _ ~t|t] t
19 _[_ t, _, _ t|~t] t
20 _[_ t, _, _ ~t|~t] t
21
22 _[_ t.t] t
23 _[_ ~t.t] t
24 _[_ t.t|t.t] t
25 _[_ ~t.t|t.t] t
26 _[_ t.t|~t.t] t
27 _[_ ~t.t|~t.t] t
28
29 _[_ t, _, _ t.t|t.t] t
30 _[_ t, _, _ ~t.t|t.t] t
31 _[_ t, _, _ t.t|~t.t] t
32 _[_ t, _, _ ~t.t|~t.t] t
33
34 _[_ struct{}] t
35 _[_ ~struct{}] t
36
37 _[_ struct{}|t] t
38 _[_ ~struct{}|t] t
39 _[_ struct{}|~t] t
40 _[_ ~struct{}|~t] t
41
42 _[_ t|struct{}] t
43 _[_ ~t|struct{}] t
44 _[_ t|~struct{}] t
45 _[_ ~t|~struct{}] t
46
47 // test cases for issue #49175
48 _[_ []t]t
49 _[_ [1]t]t
50 _[_ ~[]t]t
51 _[_ ~[1]t]t
52 t [ /* ERROR type parameters must be named */ t[0]]t
53 )
54
55 // test cases for issue #49174
56 func _[_ t]() {}
57 func _[_ []t]() {}
58 func _[_ [1]t]() {}
59 func _[_ []t | t]() {}
60 func _[_ [1]t | t]() {}
61 func _[_ t | []t]() {}
62 func _[_ []t | []t]() {}
63 func _[_ [1]t | [1]t]() {}
64 func _[_ t[t] | t[t]]() {}
65
66 // Single-expression type parameter lists and those that don't start
67 // with a (type parameter) name are considered array sizes.
68 // The term must be a valid expression (it could be a type - and then
69 // a type-checker will complain - but we don't allow ~ in the expr).
70 type (
71 _[t] t
72 _[/* ERROR unexpected ~ */ ~t] t
73 _[t|t] t
74 _[/* ERROR unexpected ~ */ ~t|t] t
75 _[t| /* ERROR unexpected ~ */ ~t] t
76 _[/* ERROR unexpected ~ */ ~t|~t] t
77 )
78
79 type (
80 _[_ t, t /* ERROR missing type constraint */ ] t
81 _[_ ~t, t /* ERROR missing type constraint */ ] t
82 _[_ t, /* ERROR type parameters must be named */ ~t] t
83 _[_ ~t, /* ERROR type parameters must be named */ ~t] t
84
85 _[_ t|t, /* ERROR type parameters must be named */ t|t] t
86 _[_ ~t|t, /* ERROR type parameters must be named */ t|t] t
87 _[_ t|t, /* ERROR type parameters must be named */ ~t|t] t
88 _[_ ~t|t, /* ERROR type parameters must be named */ ~t|t] t
89 )
90
View as plain text