Text file src/go/types/testdata/check/cycles.src

     1  // Copyright 2013 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 cycles
     6  
     7  import "unsafe"
     8  
     9  type (
    10  	T0 int
    11  	T1 /* ERROR cycle */ T1
    12  	T2 *T2
    13  
    14  	T3 /* ERROR cycle */ T4
    15  	T4 T5
    16  	T5 T3
    17  
    18  	T6 T7
    19  	T7 *T8
    20  	T8 T6
    21  
    22  	// arrays
    23  	A0 /* ERROR cycle */ [10]A0
    24  	A1 [10]*A1
    25  
    26  	A2 /* ERROR cycle */ [10]A3
    27  	A3 [10]A4
    28  	A4 A2
    29  
    30  	A5 [10]A6
    31  	A6 *A5
    32  
    33  	// slices
    34  	L0 []L0
    35  
    36  	// structs
    37  	S0 /* ERROR cycle */ struct{ _ S0 }
    38  	S1 /* ERROR cycle */ struct{ S1 }
    39  	S2 struct{ _ *S2 }
    40  	S3 struct{ *S3 }
    41  
    42  	S4 /* ERROR cycle */ struct{ S5 }
    43  	S5 struct{ S6 }
    44  	S6 S4
    45  
    46  	// pointers
    47  	P0 *P0
    48  	PP *struct{ PP.f /* ERROR no field or method f */ }
    49  
    50  	// functions
    51  	F0 func(F0)
    52  	F1 func() F1
    53  	F2 func(F2) F2
    54  
    55  	// interfaces
    56  	I0 /* ERROR cycle */ interface{ I0 }
    57  
    58  	I1 /* ERROR cycle */ interface{ I2 }
    59  	I2 interface{ I3 }
    60  	I3 interface{ I1 }
    61  
    62  	I4 interface{ f(I4) }
    63  
    64  	// testcase for issue 5090
    65  	I5 interface{ f(I6) }
    66  	I6 interface{ I5 }
    67  
    68  	// maps
    69  	M0 map[M0 /* ERROR incomparable map key */ ]M0
    70  
    71  	// channels
    72  	C0 chan C0
    73  )
    74  
    75  // test case for issue #34771
    76  type (
    77  	AA /* ERROR cycle */ B
    78  	B C
    79  	C [10]D
    80  	D E
    81  	E AA
    82  )
    83  
    84  func _() {
    85  	type (
    86  		t1 /* ERROR cycle */ t1
    87  		t2 *t2
    88  
    89  		t3 t4 /* ERROR undeclared */
    90  		t4 t5 /* ERROR undeclared */
    91  		t5 t3
    92  
    93  		// arrays
    94  		a0 /* ERROR cycle */ [10]a0
    95  		a1 [10]*a1
    96  
    97  		// slices
    98  		l0 []l0
    99  
   100  		// structs
   101  		s0 /* ERROR cycle */ struct{ _ s0 }
   102  		s1 /* ERROR cycle */ struct{ s1 }
   103  		s2 struct{ _ *s2 }
   104  		s3 struct{ *s3 }
   105  
   106  		// pointers
   107  		p0 *p0
   108  
   109  		// functions
   110  		f0 func(f0)
   111  		f1 func() f1
   112  		f2 func(f2) f2
   113  
   114  		// interfaces
   115  		i0 /* ERROR cycle */ interface{ i0 }
   116  
   117  		// maps
   118  		m0 map[m0 /* ERROR incomparable map key */ ]m0
   119  
   120  		// channels
   121  		c0 chan c0
   122  	)
   123  }
   124  
   125  // test cases for issue 6667
   126  
   127  type A [10]map[A /* ERROR incomparable map key */ ]bool
   128  
   129  type S struct {
   130  	m map[S /* ERROR incomparable map key */ ]bool
   131  }
   132  
   133  // test cases for issue 7236
   134  // (cycle detection must not be dependent on starting point of resolution)
   135  
   136  type (
   137  	P1 *T9
   138  	T9 /* ERROR cycle */ T9
   139  
   140  	T10 /* ERROR cycle */ T10
   141  	P2 *T10
   142  )
   143  
   144  func (T11) m() {}
   145  
   146  type T11 /* ERROR cycle */ struct{ T11 }
   147  
   148  type T12 /* ERROR cycle */ struct{ T12 }
   149  
   150  func (*T12) m() {}
   151  
   152  type (
   153  	P3 *T13
   154  	T13 /* ERROR cycle */ T13
   155  )
   156  
   157  // test cases for issue 18643
   158  // (type cycle detection when non-type expressions are involved)
   159  type (
   160  	T14 [len(T14 /* ERROR cycle */ {})]int
   161  	T15 [][len(T15 /* ERROR cycle */ {})]int
   162  	T16 map[[len(T16 /* ERROR cycle */ {1:2})]int]int
   163  	T17 map[int][len(T17 /* ERROR cycle */ {1:2})]int
   164  )
   165  
   166  // Test case for types depending on function literals (see also #22992).
   167  type T20 chan [unsafe.Sizeof(func(ch T20){ _ = <-ch })]byte
   168  type T22 = chan [unsafe.Sizeof(func(ch T20){ _ = <-ch })]byte
   169  
   170  func _() {
   171  	type T0 func(T0)
   172  	type T1 /* ERROR cycle */ = func(T1)
   173  	type T2 chan [unsafe.Sizeof(func(ch T2){ _ = <-ch })]byte
   174  	type T3 /* ERROR cycle */ = chan [unsafe.Sizeof(func(ch T3){ _ = <-ch })]byte
   175  }
   176  

View as plain text