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 // Examples adjusted to match new [T any] syntax for type parameters.
6 // Also, previously permitted empty type parameter lists and instantiations
7 // are now syntax errors.
8
9 package p
10
11 // crash 1
12 type nt1[_ any]interface{g /* ERROR undeclared name */ }
13 type ph1[e nt1[e],g(d /* ERROR undeclared name */ )]s /* ERROR undeclared name */
14 func(*ph1[e,e /* ERROR redeclared */ ])h(d /* ERROR undeclared name */ )
15
16 // crash 2
17 // Disabled: empty []'s are now syntax errors. This example leads to too many follow-on errors.
18 // type Numeric2 interface{t2 /* ERROR not a type */ }
19 // func t2[T Numeric2](s[]T){0 /* ERROR not a type */ []{s /* ERROR cannot index */ [0][0]}}
20
21 // crash 3
22 type t3 *interface{ t3.p /* ERROR no field or method p */ }
23
24 // crash 4
25 type Numeric4 interface{t4 /* ERROR not a type */ }
26 func t4[T Numeric4](s[]T){if( /* ERROR non-boolean */ 0){*s /* ERROR cannot indirect */ [0]}}
27
28 // crash 7
29 type foo7 interface { bar() }
30 type x7[A any] struct{ foo7 }
31 func main7() { var _ foo7 = x7[int]{} }
32
33 // crash 8
34 type foo8[A any] interface { type A }
35 func bar8[A foo8[A]](a A) {}
36 func main8() {}
37
38 // crash 9
39 type foo9[A any] interface { type foo9 /* ERROR interface contains type constraints */ [A] }
40 func _() { var _ = new(foo9 /* ERROR interface contains type constraints */ [int]) }
41
42 // crash 12
43 var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len /* ERROR must be called */ /* ERROR must be called */ )]c /* ERROR undeclared */ /* ERROR undeclared */
44
45 // crash 15
46 func y15() { var a /* ERROR declared but not used */ interface{ p() } = G15[string]{} }
47 type G15[X any] s /* ERROR undeclared name */
48 func (G15 /* ERROR generic type .* without instantiation */ ) p()
49
50 // crash 16
51 type Foo16[T any] r16 /* ERROR not a type */
52 func r16[T any]() Foo16[Foo16[T]]
53
54 // crash 17
55 type Y17 interface{ c() }
56 type Z17 interface {
57 c() Y17
58 Y17 /* ERROR duplicate method */
59 }
60 func F17[T Z17](T)
61
62 // crash 18
63 type o18[T any] []func(_ o18[[]_ /* ERROR cannot use _ */ ])
64
65 // crash 19
66 type Z19 [][[]Z19{}[0][0]]c19 /* ERROR undeclared */
67
68 // crash 20
69 type Z20 /* ERROR illegal cycle */ interface{ Z20 }
70 func F20[t Z20]() { F20(t /* ERROR invalid composite literal type */ {}) }
71
72 // crash 21
73 type Z21 /* ERROR illegal cycle */ interface{ Z21 }
74 func F21[T Z21]() { ( /* ERROR not used */ F21[Z21]) }
75
76 // crash 24
77 type T24[P any] P
78 func (r T24[P]) m() { T24 /* ERROR without instantiation */ .m() }
79
80 // crash 25
81 type T25[A any] int
82 func (t T25[A]) m1() {}
83 var x T25 /* ERROR without instantiation */ .m1
84
85 // crash 26
86 type T26 = interface{ F26[ /* ERROR methods cannot have type parameters */ Z any]() }
87 func F26[Z any]() T26 { return F26[] /* ERROR operand */ }
88
89 // crash 27
90 func e27[T any]() interface{ x27 /* ERROR not a type */ }
91 func x27() { e27 /* ERROR cannot infer T */ () }
92
View as plain text