Source file src/internal/types/testdata/check/cycles0.go

     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 "invalid recursive type: T1 refers to itself" */ T1
    12  	T2 *T2
    13  
    14  	T3 /* ERROR "invalid recursive type" */ T4
    15  	T4 T5
    16  	T5 T3
    17  
    18  	T6 T7
    19  	T7 *T8
    20  	T8 T6
    21  
    22  	// arrays
    23  	A0 /* ERROR "invalid recursive type" */ [10]A0
    24  	A1 [10]*A1
    25  
    26  	A2 /* ERROR "invalid recursive type" */ [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 "invalid recursive type: S0 refers to itself" */ struct{ _ S0 }
    38  	S1 /* ERROR "invalid recursive type: S1 refers to itself" */ struct{ S1 }
    39  	S2 struct{ _ *S2 }
    40  	S3 struct{ *S3 }
    41  
    42  	S4 /* ERROR "invalid recursive type" */ struct{ S5 }
    43  	S5 struct{ S6 }
    44  	S6 S4
    45  
    46  	// pointers
    47  	P0 *P0
    48  	PP *struct{ PP.f /* ERROR "PP.f is not a type" */ }
    49  
    50  	// functions
    51  	F0 func(F0)
    52  	F1 func() F1
    53  	F2 func(F2) F2
    54  
    55  	// interfaces
    56  	I0 /* ERROR "invalid recursive type: I0 refers to itself" */ interface{ I0 }
    57  
    58  	I1 /* ERROR "invalid recursive type" */ 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 "invalid map key" */ ]M0
    70  
    71  	// channels
    72  	C0 chan C0
    73  )
    74  
    75  // test case for issue #34771
    76  type (
    77  	AA /* ERROR "invalid recursive type" */ B
    78  	B C
    79  	C [10]D
    80  	D E
    81  	E AA
    82  )
    83  
    84  func _() {
    85  	type (
    86  		t1 /* ERROR "invalid recursive type: t1 refers to itself" */ t1
    87  		t2 *t2
    88  
    89  		t3 t4 /* ERROR "undefined" */
    90  		t4 t5 /* ERROR "undefined" */
    91  		t5 t3
    92  
    93  		// arrays
    94  		a0 /* ERROR "invalid recursive type: a0 refers to itself" */ [10]a0
    95  		a1 [10]*a1
    96  
    97  		// slices
    98  		l0 []l0
    99  
   100  		// structs
   101  		s0 /* ERROR "invalid recursive type: s0 refers to itself" */ struct{ _ s0 }
   102  		s1 /* ERROR "invalid recursive type: s1 refers to itself" */ 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 "invalid recursive type: i0 refers to itself" */ interface{ i0 }
   116  
   117  		// maps
   118  		m0 map[m0 /* ERROR "invalid 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 "invalid map key" */ ]bool
   128  
   129  type S struct {
   130  	m map[S /* ERROR "invalid 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 "invalid recursive type: T9 refers to itself" */ T9
   139  
   140  	T10 /* ERROR "invalid recursive type: T10 refers to itself" */ T10
   141  	P2 *T10
   142  )
   143  
   144  func (T11) m() {}
   145  
   146  type T11 /* ERROR "invalid recursive type: T11 refers to itself" */ struct{ T11 }
   147  
   148  type T12 /* ERROR "invalid recursive type: T12 refers to itself" */ struct{ T12 }
   149  
   150  func (*T12) m() {}
   151  
   152  type (
   153  	P3 *T13
   154  	T13 /* ERROR "invalid recursive type" */ 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 "invalid recursive type" */ {})]int
   161  	T15 [][len(T15 /* ERROR "invalid recursive type" */ {})]int
   162  	T16 map[[len(T16 /* ERROR "invalid recursive type" */ {1:2})]int]int
   163  	T17 map[int][len(T17 /* ERROR "invalid recursive type" */ {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 "invalid recursive type" */ = func(T1)
   173  	type T2 chan [unsafe.Sizeof(func(ch T2){ _ = <-ch })]byte
   174  	type T3 /* ERROR "invalid recursive type" */ = chan [unsafe.Sizeof(func(ch T3){ _ = <-ch })]byte
   175  }
   176  

View as plain text