aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47818.go2
blob: 5334695b5e9e28b982c70057f76c91278d5d34c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Parser accepts type parameters but the type checker
// needs to report any operations that are not permitted
// before Go 1.18.

package go1_17

type T[P /* ERROR type parameters require go1\.18 or later */ any] struct{}

// for init (and main, but we're not in package main) we should only get one error
func init[P /* ERROR func init must have no type parameters */ any]()   {}
func main[P /* ERROR type parameters require go1\.18 or later */ any]() {}

func f[P /* ERROR type parameters require go1\.18 or later */ any](x P) {
	var _ T[ /* ERROR type instantiation requires go1\.18 or later */ int]
	var _ (T[ /* ERROR type instantiation requires go1\.18 or later */ int])
	_ = T[ /* ERROR type instantiation requires go1\.18 or later */ int]{}
	_ = T[ /* ERROR type instantiation requires go1\.18 or later */ int](struct{}{})
}

func (T[ /* ERROR type instantiation requires go1\.18 or later */ P]) g(x int) {
	f[ /* ERROR function instantiation requires go1\.18 or later */ int](0)     // explicit instantiation
	(f[ /* ERROR function instantiation requires go1\.18 or later */ int])(0)   // parentheses (different code path)
	f( /* ERROR implicit function instantiation requires go1\.18 or later */ x) // implicit instantiation
}

type C1 interface {
	comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
}

type C2 interface {
	comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
	int        // ERROR embedding non-interface type int requires go1\.18 or later
	~ /* ERROR embedding interface element ~int requires go1\.18 or later */ int
	int /* ERROR embedding interface element int\|~string requires go1\.18 or later */ | ~string
}

type _ interface {
	// errors for these were reported with their declaration
	C1
	C2
}

type (
	_ comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
	// errors for these were reported with their declaration
	_ C1
	_ C2

	_ = comparable // ERROR undeclared name: comparable \(requires version go1\.18 or later\)
	// errors for these were reported with their declaration
	_ = C1
	_ = C2
)

// TODO(gri) need test cases for imported constraint types (see also issue #47967)