github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/src/go/types/testdata/decls0.src (about) 1 // Copyright 2011 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 // type declarations 6 7 package decls0 8 9 import "unsafe" 10 11 const pi = 3.1415 12 13 type ( 14 N undeclared /* ERROR "undeclared" */ 15 B bool 16 I int32 17 A [10]P 18 T struct { 19 x, y P 20 } 21 P *T 22 R (*R) 23 F func(A) I 24 Y interface { 25 f(A) I 26 } 27 S [](((P))) 28 M map[I]F 29 C chan<- I 30 31 // blank types must be typechecked 32 _ pi /* ERROR "not a type" */ 33 _ struct{} 34 _ struct{ pi /* ERROR "not a type" */ } 35 ) 36 37 38 // declarations of init 39 const _, init /* ERROR "cannot declare init" */ , _ = 0, 1, 2 40 type init /* ERROR "cannot declare init" */ struct{} 41 var _, init /* ERROR "cannot declare init" */ int 42 43 func init() {} 44 func init /* ERROR "missing function body" */ () 45 46 func _() { const init = 0 } 47 func _() { type init int } 48 func _() { var init int; _ = init } 49 50 // invalid array types 51 type ( 52 iA0 [... /* ERROR "invalid use of '...'" */ ]byte 53 iA1 [1 /* ERROR "invalid array length" */ <<100]int 54 iA2 [- /* ERROR "invalid array length" */ 1]complex128 55 iA3 ["foo" /* ERROR "must be integer" */ ]string 56 ) 57 58 59 type ( 60 p1 pi /* ERROR "no field or method foo" */ .foo 61 p2 unsafe.Pointer 62 ) 63 64 65 type ( 66 Pi pi /* ERROR "not a type" */ 67 68 a /* ERROR "illegal cycle" */ a 69 a /* ERROR "redeclared" */ int 70 71 // where the cycle error appears depends on the 72 // order in which declarations are processed 73 // (which depends on the order in which a map 74 // is iterated through) 75 b /* ERROR "illegal cycle" */ c 76 c d 77 d e 78 e b 79 80 t *t 81 82 U V 83 V *W 84 W U 85 86 P1 *S2 87 P2 P1 88 89 S0 struct { 90 } 91 S1 struct { 92 a, b, c int 93 u, v, a /* ERROR "redeclared" */ float32 94 } 95 S2 struct { 96 S0 // anonymous field 97 S0 /* ERROR "redeclared" */ int 98 } 99 S3 struct { 100 x S2 101 } 102 S4/* ERROR "illegal cycle" */ struct { 103 S4 104 } 105 S5 /* ERROR "illegal cycle" */ struct { 106 S6 107 } 108 S6 struct { 109 field S7 110 } 111 S7 struct { 112 S5 113 } 114 115 L1 []L1 116 L2 []int 117 118 A1 [10.0]int 119 A2 /* ERROR "illegal cycle" */ [10]A2 120 A3 /* ERROR "illegal cycle" */ [10]struct { 121 x A4 122 } 123 A4 [10]A3 124 125 F1 func() 126 F2 func(x, y, z float32) 127 F3 func(x, y, x /* ERROR "redeclared" */ float32) 128 F4 func() (x, y, x /* ERROR "redeclared" */ float32) 129 F5 func(x int) (x /* ERROR "redeclared" */ float32) 130 F6 func(x ...int) 131 132 I1 interface{} 133 I2 interface { 134 m1() 135 } 136 I3 interface { 137 m1() 138 m1 /* ERROR "redeclared" */ () 139 } 140 I4 interface { 141 m1(x, y, x /* ERROR "redeclared" */ float32) 142 m2() (x, y, x /* ERROR "redeclared" */ float32) 143 m3(x int) (x /* ERROR "redeclared" */ float32) 144 } 145 I5 interface { 146 m1(I5) 147 } 148 I6 interface { 149 S0 /* ERROR "not an interface" */ 150 } 151 I7 interface { 152 I1 153 I1 154 } 155 I8 /* ERROR "illegal cycle" */ interface { 156 I8 157 } 158 I9 interface { 159 I10 160 } 161 I10 interface { 162 I11 163 } 164 I11 /* ERROR "illegal cycle" */ interface { 165 I9 166 } 167 168 C1 chan int 169 C2 <-chan int 170 C3 chan<- C3 171 C4 chan C5 172 C5 chan C6 173 C6 chan C4 174 175 M1 map[Last]string 176 M2 map[string]M2 177 178 Last int 179 ) 180 181 // cycles in function/method declarations 182 // (test cases for issue 5217 and variants) 183 func f1(x f1 /* ERROR "not a type" */ ) {} 184 func f2(x *f2 /* ERROR "not a type" */ ) {} 185 func f3() (x f3 /* ERROR "not a type" */ ) { return } 186 func f4() (x *f4 /* ERROR "not a type" */ ) { return } 187 188 func (S0) m1(x S0 /* ERROR "field or method" */ .m1) {} 189 func (S0) m2(x *S0 /* ERROR "field or method" */ .m2) {} 190 func (S0) m3() (x S0 /* ERROR "field or method" */ .m3) { return } 191 func (S0) m4() (x *S0 /* ERROR "field or method" */ .m4) { return } 192 193 // interfaces may not have any blank methods 194 type BlankI interface { 195 _ /* ERROR "invalid method name" */ () 196 _ /* ERROR "invalid method name" */ (float32) int 197 m() 198 } 199 200 // non-interface types may have multiple blank methods 201 type BlankT struct{} 202 203 func (BlankT) _() {} 204 func (BlankT) _(int) {} 205 func (BlankT) _() int { return 0 } 206 func (BlankT) _(int) int { return 0}