Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: go/types/testdata/check

     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  
    49  	// functions
    50  	F0 func(F0)
    51  	F1 func() F1
    52  	F2 func(F2) F2
    53  
    54  	// interfaces
    55  	I0 /* ERROR cycle */ interface{ I0 }
    56  
    57  	I1 /* ERROR cycle */ interface{ I2 }
    58  	I2 interface{ I3 }
    59  	I3 interface{ I1 }
    60  
    61  	I4 interface{ f(I4) }
    62  
    63  	// testcase for issue 5090
    64  	I5 interface{ f(I6) }
    65  	I6 interface{ I5 }
    66  
    67  	// maps
    68  	M0 map[M0 /* ERROR incomparable map key */ ]M0
    69  
    70  	// channels
    71  	C0 chan C0
    72  )
    73  
    74  // test case for issue #34771
    75  type (
    76  	AA /* ERROR cycle */ B
    77  	B C
    78  	C [10]D
    79  	D E
    80  	E AA
    81  )
    82  
    83  func _() {
    84  	type (
    85  		t1 /* ERROR cycle */ t1
    86  		t2 *t2
    87  
    88  		t3 t4 /* ERROR undeclared */
    89  		t4 t5 /* ERROR undeclared */
    90  		t5 t3
    91  
    92  		// arrays
    93  		a0 /* ERROR cycle */ [10]a0
    94  		a1 [10]*a1
    95  
    96  		// slices
    97  		l0 []l0
    98  
    99  		// structs
   100  		s0 /* ERROR cycle */ struct{ _ s0 }
   101  		s1 /* ERROR cycle */ struct{ s1 }
   102  		s2 struct{ _ *s2 }
   103  		s3 struct{ *s3 }
   104  
   105  		// pointers
   106  		p0 *p0
   107  
   108  		// functions
   109  		f0 func(f0)
   110  		f1 func() f1
   111  		f2 func(f2) f2
   112  
   113  		// interfaces
   114  		i0 /* ERROR cycle */ interface{ i0 }
   115  
   116  		// maps
   117  		m0 map[m0 /* ERROR incomparable map key */ ]m0
   118  
   119  		// channels
   120  		c0 chan c0
   121  	)
   122  }
   123  
   124  // test cases for issue 6667
   125  
   126  type A [10]map[A /* ERROR incomparable map key */ ]bool
   127  
   128  type S struct {
   129  	m map[S /* ERROR incomparable map key */ ]bool
   130  }
   131  
   132  // test cases for issue 7236
   133  // (cycle detection must not be dependent on starting point of resolution)
   134  
   135  type (
   136  	P1 *T9
   137  	T9 /* ERROR cycle */ T9
   138  
   139  	T10 /* ERROR cycle */ T10
   140  	P2 *T10
   141  )
   142  
   143  func (T11) m() {}
   144  
   145  type T11 /* ERROR cycle */ struct{ T11 }
   146  
   147  type T12 /* ERROR cycle */ struct{ T12 }
   148  
   149  func (*T12) m() {}
   150  
   151  type (
   152  	P3 *T13
   153  	T13 /* ERROR cycle */ T13
   154  )
   155  
   156  // test cases for issue 18643
   157  // (type cycle detection when non-type expressions are involved)
   158  type (
   159  	T14 [len(T14 /* ERROR cycle */ {})]int
   160  	T15 [][len(T15 /* ERROR cycle */ {})]int
   161  	T16 map[[len(T16 /* ERROR cycle */ {1:2})]int]int
   162  	T17 map[int][len(T17 /* ERROR cycle */ {1:2})]int
   163  )
   164  
   165  // Test case for types depending on function literals (see also #22992).
   166  type T20 chan [unsafe.Sizeof(func(ch T20){ _ = <-ch })]byte
   167  type T22 = chan [unsafe.Sizeof(func(ch T20){ _ = <-ch })]byte
   168  
   169  func _() {
   170  	type T0 func(T0)
   171  	type T1 /* ERROR cycle */ = func(T1)
   172  	type T2 chan [unsafe.Sizeof(func(ch T2){ _ = <-ch })]byte
   173  	type T3 /* ERROR cycle */ = chan [unsafe.Sizeof(func(ch T3){ _ = <-ch })]byte
   174  }
   175  

View as plain text