blob: 6667ba4fec08551412c380b4cc0a34d413625ca6 [file] [log] [blame]
Dan Willemsenbc60c3c2021-12-15 01:09:00 -08001// 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
5package p
6
7// parameterized types with self-recursive constraints
8type (
9 T1 /* ERROR illegal cycle */ [P T1[P]] interface{}
10 T2 /* ERROR illegal cycle */ [P, Q T2[P, Q]] interface{}
11 T3[P T2[P, Q], Q interface{ ~string }] interface{}
12
13 T4a /* ERROR illegal cycle */ [P T4a[P]] interface{ ~int }
14 T4b /* ERROR illegal cycle */ [P T4b[int]] interface{ ~int }
15 T4c /* ERROR illegal cycle */ [P T4c[string]] interface{ ~int }
16
17 // mutually recursive constraints
18 T5 /* ERROR illegal cycle */ [P T6[P]] interface{ int }
19 T6[P T5[P]] interface{ int }
20)
21
22// verify that constraints are checked as expected
23var (
24 _ T1[int]
25 _ T2[int, string]
26 _ T3[int, string]
27)
28
29// test case from issue
30
31type Eq /* ERROR illegal cycle */ [a Eq[a]] interface {
32 Equal(that a) bool
33}