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 // Parser accepts type parameters but the type checker
6 // needs to report any operations that are not permitted
7 // before Go 1.18.
8
9 package go1_17
10
11 type T[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ] struct{}
12
13 // for init (and main, but we're not in package main) we should only get one error
14 func init[P /* ERROR func init must have no type parameters */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ]() {}
15 func main[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ]() {}
16
17 func f[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ](x P) {
18 var _ T[ /* ERROR type instantiation requires go1\.18 or later */ int]
19 var _ (T[ /* ERROR type instantiation requires go1\.18 or later */ int])
20 _ = T[ /* ERROR type instantiation requires go1\.18 or later */ int]{}
21 _ = T[ /* ERROR type instantiation requires go1\.18 or later */ int](struct{}{})
22 }
23
24 func (T[ /* ERROR type instantiation requires go1\.18 or later */ P]) g(x int) {
25 f[ /* ERROR function instantiation requires go1\.18 or later */ int](0) // explicit instantiation
26 (f[ /* ERROR function instantiation requires go1\.18 or later */ int])(0) // parentheses (different code path)
27 f( /* ERROR implicit function instantiation requires go1\.18 or later */ x) // implicit instantiation
28 }
29
30 type C1 interface {
31 comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
32 }
33
34 type C2 interface {
35 comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
36 int // ERROR embedding non-interface type int requires go1\.18 or later
37 ~ /* ERROR embedding interface element ~int requires go1\.18 or later */ int
38 int /* ERROR embedding interface element int\|~string requires go1\.18 or later */ | ~string
39 }
40
41 type _ interface {
42 // errors for these were reported with their declaration
43 C1
44 C2
45 }
46
47 type (
48 _ comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
49 // errors for these were reported with their declaration
50 _ C1
51 _ C2
52
53 _ = comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
54 // errors for these were reported with their declaration
55 _ = C1
56 _ = C2
57 )
58
View as plain text