Source file src/internal/types/testdata/fixedbugs/issue52698.go

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

View as plain text