1// Copyright 2022 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// correctness check: ensure that cycles through generic instantiations are detected
8type T[P any] struct {
9	_ P
10}
11
12type S /* ERROR "invalid recursive type" */ struct {
13	_ T[S]
14}
15
16// simplified test 1
17
18var _ A1[A1[string]]
19
20type A1[P any] struct {
21	_ B1[P]
22}
23
24type B1[P any] struct {
25	_ P
26}
27
28// simplified test 2
29var _ B2[A2]
30
31type A2 struct {
32	_ B2[string]
33}
34
35type B2[P any] struct {
36	_ C2[P]
37}
38
39type C2[P any] struct {
40	_ P
41}
42
43// test case from issue
44type T23 interface {
45	~struct {
46		Field0 T13[T15]
47	}
48}
49
50type T1[P1 interface {
51}] struct {
52	Field2 P1
53}
54
55type T13[P2 interface {
56}] struct {
57	Field2 T1[P2]
58}
59
60type T15 struct {
61	Field0 T13[string]
62}
63