github.com/aloncn/graphics-go@v0.0.1/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 // The error message below could be better. At the moment 54 // we believe an integer that is too large is not an integer. 55 // But at least we get an error. 56 iA1 [1 /* ERROR "must be integer" */ <<100]int 57 iA2 [- /* ERROR "invalid array length" */ 1]complex128 58 iA3 ["foo" /* ERROR "must be integer" */ ]string 59 iA4 [float64 /* ERROR "must be integer" */ (0)]int 60 ) 61 62 63 type ( 64 p1 pi /* ERROR "no field or method foo" */ .foo 65 p2 unsafe.Pointer 66 ) 67 68 69 type ( 70 Pi pi /* ERROR "not a type" */ 71 72 a /* ERROR "illegal cycle" */ a 73 a /* ERROR "redeclared" */ int 74 75 // where the cycle error appears depends on the 76 // order in which declarations are processed 77 // (which depends on the order in which a map 78 // is iterated through) 79 b /* ERROR "illegal cycle" */ c 80 c d 81 d e 82 e b 83 84 t *t 85 86 U V 87 V *W 88 W U 89 90 P1 *S2 91 P2 P1 92 93 S0 struct { 94 } 95 S1 struct { 96 a, b, c int 97 u, v, a /* ERROR "redeclared" */ float32 98 } 99 S2 struct { 100 S0 // anonymous field 101 S0 /* ERROR "redeclared" */ int 102 } 103 S3 struct { 104 x S2 105 } 106 S4/* ERROR "illegal cycle" */ struct { 107 S4 108 } 109 S5 /* ERROR "illegal cycle" */ struct { 110 S6 111 } 112 S6 struct { 113 field S7 114 } 115 S7 struct { 116 S5 117 } 118 119 L1 []L1 120 L2 []int 121 122 A1 [10.0]int 123 A2 /* ERROR "illegal cycle" */ [10]A2 124 A3 /* ERROR "illegal cycle" */ [10]struct { 125 x A4 126 } 127 A4 [10]A3 128 129 F1 func() 130 F2 func(x, y, z float32) 131 F3 func(x, y, x /* ERROR "redeclared" */ float32) 132 F4 func() (x, y, x /* ERROR "redeclared" */ float32) 133 F5 func(x int) (x /* ERROR "redeclared" */ float32) 134 F6 func(x ...int) 135 136 I1 interface{} 137 I2 interface { 138 m1() 139 } 140 I3 interface { 141 m1() 142 m1 /* ERROR "redeclared" */ () 143 } 144 I4 interface { 145 m1(x, y, x /* ERROR "redeclared" */ float32) 146 m2() (x, y, x /* ERROR "redeclared" */ float32) 147 m3(x int) (x /* ERROR "redeclared" */ float32) 148 } 149 I5 interface { 150 m1(I5) 151 } 152 I6 interface { 153 S0 /* ERROR "not an interface" */ 154 } 155 I7 interface { 156 I1 157 I1 158 } 159 I8 /* ERROR "illegal cycle" */ interface { 160 I8 161 } 162 I9 interface { 163 I10 164 } 165 I10 interface { 166 I11 167 } 168 I11 /* ERROR "illegal cycle" */ interface { 169 I9 170 } 171 172 C1 chan int 173 C2 <-chan int 174 C3 chan<- C3 175 C4 chan C5 176 C5 chan C6 177 C6 chan C4 178 179 M1 map[Last]string 180 M2 map[string]M2 181 182 Last int 183 ) 184 185 // cycles in function/method declarations 186 // (test cases for issue 5217 and variants) 187 func f1(x f1 /* ERROR "not a type" */ ) {} 188 func f2(x *f2 /* ERROR "not a type" */ ) {} 189 func f3() (x f3 /* ERROR "not a type" */ ) { return } 190 func f4() (x *f4 /* ERROR "not a type" */ ) { return } 191 192 func (S0) m1(x S0 /* ERROR "field or method" */ .m1) {} 193 func (S0) m2(x *S0 /* ERROR "field or method" */ .m2) {} 194 func (S0) m3() (x S0 /* ERROR "field or method" */ .m3) { return } 195 func (S0) m4() (x *S0 /* ERROR "field or method" */ .m4) { return } 196 197 // interfaces may not have any blank methods 198 type BlankI interface { 199 _ /* ERROR "invalid method name" */ () 200 _ /* ERROR "invalid method name" */ (float32) int 201 m() 202 } 203 204 // non-interface types may have multiple blank methods 205 type BlankT struct{} 206 207 func (BlankT) _() {} 208 func (BlankT) _(int) {} 209 func (BlankT) _() int { return 0 } 210 func (BlankT) _(int) int { return 0}