github.com/zebozhuang/go@v0.0.0-20200207033046-f8a98f6f5c5d/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 /* ERROR Nosuchtype not declared by package fmt */ .Nosuchtype 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 }