github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/src/go/types/testdata/issues.src (about) 1 // Copyright 2014 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 issues 6 7 import "fmt" 8 9 func issue7035() { 10 type T struct{ X int } 11 _ = func() { 12 fmt.Println() // must refer to imported fmt rather than the fmt below 13 } 14 fmt := new(T) 15 _ = fmt.X 16 } 17 18 func issue8066() { 19 const ( 20 _ = float32(340282356779733661637539395458142568447) 21 _ = float32(340282356779733661637539395458142568448 /* ERROR cannot convert */ ) 22 ) 23 } 24 25 // Check that a missing identifier doesn't lead to a spurious error cascade. 26 func issue8799a() { 27 x, ok := missing /* ERROR undeclared */ () 28 _ = !ok 29 _ = x 30 } 31 32 func issue8799b(x int, ok bool) { 33 x, ok = missing /* ERROR undeclared */ () 34 _ = !ok 35 _ = x 36 } 37 38 func issue9182() { 39 type Point C /* ERROR undeclared */ .Point 40 // no error for composite literal based on unknown type 41 _ = Point{x: 1, y: 2} 42 } 43 44 func f0() (a []int) { return } 45 func f1() (a []int, b int) { return } 46 func f2() (a, b []int) { return } 47 48 func append_([]int, ...int) {} 49 50 func issue9473(a []int, b ...int) { 51 // variadic builtin function 52 _ = append(f0()) 53 _ = append(f0(), f0()...) 54 _ = append(f1()) 55 _ = append(f2 /* ERROR cannot use .* in argument */ ()) 56 _ = append(f2()... /* ERROR cannot use ... */ ) 57 _ = append(f0(), f1 /* ERROR 2-valued f1 */ ()) 58 _ = append(f0(), f2 /* ERROR 2-valued f2 */ ()) 59 _ = append(f0(), f1 /* ERROR 2-valued f1 */ ()...) 60 _ = append(f0(), f2 /* ERROR 2-valued f2 */ ()...) 61 62 // variadic user-defined function 63 append_(f0()) 64 append_(f0(), f0()...) 65 append_(f1()) 66 append_(f2 /* ERROR cannot use .* in argument */ ()) 67 append_(f2()... /* ERROR cannot use ... */ ) 68 append_(f0(), f1 /* ERROR 2-valued f1 */ ()) 69 append_(f0(), f2 /* ERROR 2-valued f2 */ ()) 70 append_(f0(), f1 /* ERROR 2-valued f1 */ ()...) 71 append_(f0(), f2 /* ERROR 2-valued f2 */ ()...) 72 } 73 74 // Check that embedding a non-interface type in an interface results in a good error message. 75 func issue10979() { 76 type _ interface { 77 int /* ERROR int is not an interface */ 78 } 79 type T struct{} 80 type _ interface { 81 T /* ERROR T is not an interface */ 82 } 83 type _ interface { 84 nosuchtype /* ERROR undeclared name: nosuchtype */ 85 } 86 type _ interface { 87 fmt.Nosuchtype /* ERROR Nosuchtype not declared by package fmt */ 88 } 89 type _ interface { 90 nosuchpkg /* ERROR undeclared name: nosuchpkg */ .Nosuchtype 91 } 92 type I interface { 93 I /* ERROR I\.m \(value of type func\(I\)\) is not a type */ .m 94 m() 95 } 96 } 97 98 // issue11347 99 // These should not crash. 100 var a1, b1 /* ERROR cycle */ , c1 /* ERROR cycle */ b1 = 0 > 0<<""[""[c1]]>c1 101 var a2, b2 /* ERROR cycle */ = 0 /* ERROR cannot initialize */ /* ERROR cannot initialize */ > 0<<""[b2] 102 var a3, b3 /* ERROR cycle */ = int /* ERROR cannot initialize */ /* ERROR cannot initialize */ (1<<""[b3]) 103 104 // issue10260 105 // Check that error messages explain reason for interface assignment failures. 106 type ( 107 I0 interface{} 108 I1 interface{ foo() } 109 I2 interface{ foo(x int) } 110 T0 struct{} 111 T1 struct{} 112 T2 struct{} 113 ) 114 115 func (*T1) foo() {} 116 func (*T2) foo(x int) {} 117 118 func issue10260() { 119 var ( 120 i0 I0 121 i1 I1 122 i2 I2 123 t0 *T0 124 t1 *T1 125 t2 *T2 126 ) 127 i1 = i0 /* ERROR cannot use .* missing method foo */ 128 i1 = t0 /* ERROR cannot use .* missing method foo */ 129 i1 = i2 /* ERROR cannot use .* wrong type for method foo */ 130 i1 = t2 /* ERROR cannot use .* wrong type for method foo */ 131 i2 = i1 /* ERROR cannot use .* wrong type for method foo */ 132 i2 = t1 /* ERROR cannot use .* wrong type for method foo */ 133 134 _ = func() I1 { return i0 /* ERROR cannot use .* missing method foo */ } 135 _ = func() I1 { return t0 /* ERROR cannot use .* missing method foo */ } 136 _ = func() I1 { return i2 /* ERROR cannot use .* wrong type for method foo */ } 137 _ = func() I1 { return t2 /* ERROR cannot use .* wrong type for method foo */ } 138 _ = func() I2 { return i1 /* ERROR cannot use .* wrong type for method foo */ } 139 _ = func() I2 { return t1 /* ERROR cannot use .* wrong type for method foo */ } 140 141 // a few more - less exhaustive now 142 143 f := func(I1, I2){} 144 f(i0 /* ERROR cannot use .* missing method foo */ , i1 /* ERROR cannot use .* wrong type for method foo */) 145 146 _ = [...]I1{i0 /* ERROR cannot use .* missing method foo */ } 147 _ = [...]I1{i2 /* ERROR cannot use .* wrong type for method foo */ } 148 _ = []I1{i0 /* ERROR cannot use .* missing method foo */ } 149 _ = []I1{i2 /* ERROR cannot use .* wrong type for method foo */ } 150 _ = map[int]I1{0: i0 /* ERROR cannot use .* missing method foo */ } 151 _ = map[int]I1{0: i2 /* ERROR cannot use .* wrong type for method foo */ } 152 153 make(chan I1) <- i0 /* ERROR cannot use .* in send: missing method foo */ 154 make(chan I1) <- i2 /* ERROR cannot use .* in send: wrong type for method foo */ 155 } 156 157 // Check that constants representable as integers are in integer form 158 // before being used in operations that are only defined on integers. 159 func issue14229() { 160 // from the issue 161 const _ = int64(-1<<63) % 1e6 162 163 // related 164 const ( 165 a int = 3 166 b = 4.0 167 _ = a / b 168 _ = a % b 169 _ = b / a 170 _ = b % a 171 ) 172 } 173 174 // Check that in a n:1 variable declaration with type and initialization 175 // expression the type is distributed to all variables of the lhs before 176 // the initialization expression assignment is checked. 177 func issue15755() { 178 // from issue 179 var i interface{} 180 type b bool 181 var x, y b = i.(b) 182 _ = x == y 183 184 // related: we should see an error since the result of f1 is ([]int, int) 185 var u, v []int = f1 /* ERROR cannot use f1 */ () 186 _ = u 187 _ = v 188 } 189 190 // Test that we don't get "declared but not used" 191 // errors in the context of invalid/C objects. 192 func issue20358() { 193 var F C /* ERROR "undeclared" */ .F 194 var A C /* ERROR "undeclared" */ .A 195 var S C /* ERROR "undeclared" */ .S 196 type T C /* ERROR "undeclared" */ .T 197 type P C /* ERROR "undeclared" */ .P 198 199 // these variables must be "used" even though 200 // the LHS expressions/types below in which 201 // context they are used are unknown/invalid 202 var f, a, s1, s2, s3, t, p int 203 204 _ = F(f) 205 _ = A[a] 206 _ = S[s1:s2:s3] 207 _ = T{t} 208 _ = P{f: p} 209 } 210 211 // Test that we don't declare lhs variables in short variable 212 // declarations before we type-check function literals on the 213 // rhs. 214 func issue24026() { 215 f := func() int { f(0) /* must refer to outer f */; return 0 } 216 _ = f 217 218 _ = func() { 219 f := func() { _ = f() /* must refer to outer f */ } 220 _ = f 221 } 222 223 // b and c must not be visible inside function literal 224 a := 0 225 a, b, c := func() (int, int, int) { 226 return a, b /* ERROR undeclared */ , c /* ERROR undeclared */ 227 }() 228 _, _ = b, c 229 } 230 231 func f(int) {} // for issue24026 232 233 // Test that we don't report a "missing return statement" error 234 // (due to incorrect context when type-checking interfaces). 235 func issue24140(x interface{}) int { 236 switch x.(type) { 237 case interface{}: 238 return 0 239 default: 240 panic(0) 241 } 242 } 243 244 // Test that we don't crash when the 'if' condition is missing. 245 func issue25438() { 246 if { /* ERROR missing condition */ } 247 if x := 0; /* ERROR missing condition */ { _ = x } 248 if 249 { /* ERROR missing condition */ } 250 } 251 252 // Test that we can embed alias type names in interfaces. 253 type issue25301 interface { 254 E 255 } 256 257 type E = interface { 258 m() 259 } 260 261 // Test case from issue. Eventually we may disallow this due 262 // to the cycle via the alias type name. But for now we make 263 // sure this is accepted. 264 type issue25301b = interface { 265 m() interface{ issue25301b } 266 } 267 268 type issue25301c interface { 269 notE // ERROR struct\{\} is not an interface 270 } 271 272 type notE = struct{} 273 274 // Test that method declarations don't introduce artificial cycles 275 // (issue #26124). 276 const CC TT = 1 277 type TT int 278 func (TT) MM() [CC]TT 279 280 // Reduced test case from issue #26124. 281 const preloadLimit LNumber = 128 282 type LNumber float64 283 func (LNumber) assertFunction() *LFunction 284 type LFunction struct { 285 GFunction LGFunction 286 } 287 type LGFunction func(*LState) 288 type LState struct { 289 reg *registry 290 } 291 type registry struct { 292 alloc *allocator 293 } 294 type allocator struct { 295 _ [int(preloadLimit)]int 296 } 297 298 // Test that we don't crash when type-checking composite literals 299 // containing errors in the type. 300 var issue27346 = [][n /* ERROR undeclared */ ]int{ 301 0: {}, 302 } 303 304 var issue22467 = map[int][... /* ERROR invalid use of ... */ ]int{0: {}} 305 306 // Test that invalid use of ... in parameter lists is recognized 307 // (issue #28281). 308 func issue28281a(int, int, ...int) 309 func issue28281b(a, b int, c ...int) 310 func issue28281c(a, b, c ... /* ERROR can only use ... with final parameter */ int) 311 func issue28281d(... /* ERROR can only use ... with final parameter */ int, int) 312 func issue28281e(a, b, c ... /* ERROR can only use ... with final parameter */ int, d int) 313 func issue28281f(... /* ERROR can only use ... with final parameter */ int, ... /* ERROR can only use ... with final parameter */ int, int) 314 func (... /* ERROR expected type */ TT) f() 315 func issue28281g() (... /* ERROR expected type */ TT)