github.com/aloncn/graphics-go@v0.0.1/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 mismatch */ /* ERROR mismatch */ > 0<<""[b2] 102 var a3, b3 /* ERROR cycle */ = int /* ERROR mismatch */ /* ERROR mismatch */ (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 }