github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/test/assign1.go (about) 1 // errorcheck 2 3 // Copyright 2009 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Verify assignment rules are enforced by the compiler. 8 // Does not compile. 9 10 package main 11 12 type ( 13 A [10]int 14 B []int 15 C chan int 16 F func() int 17 I interface { 18 m() int 19 } 20 M map[int]int 21 P *int 22 S struct { 23 X int 24 } 25 26 A1 [10]int 27 B1 []int 28 C1 chan int 29 F1 func() int 30 I1 interface { 31 m() int 32 } 33 M1 map[int]int 34 P1 *int 35 S1 struct { 36 X int 37 } 38 ) 39 40 var ( 41 a0 [10]int 42 b0 []int 43 c0 chan int 44 f0 func() int 45 i0 interface { 46 m() int 47 } 48 m0 map[int]int 49 p0 *int 50 s0 struct { 51 X int 52 } 53 54 a A 55 b B 56 c C 57 f F 58 i I 59 m M 60 p P 61 s S 62 63 a1 A1 64 b1 B1 65 c1 C1 66 f1 F1 67 i1 I1 68 m1 M1 69 p1 P1 70 s1 S1 71 72 pa0 *[10]int 73 pb0 *[]int 74 pc0 *chan int 75 pf0 *func() int 76 pi0 *interface { 77 m() int 78 } 79 pm0 *map[int]int 80 pp0 **int 81 ps0 *struct { 82 X int 83 } 84 85 pa *A 86 pb *B 87 pc *C 88 pf *F 89 pi *I 90 pm *M 91 pp *P 92 ps *S 93 94 pa1 *A1 95 pb1 *B1 96 pc1 *C1 97 pf1 *F1 98 pi1 *I1 99 pm1 *M1 100 pp1 *P1 101 ps1 *S1 102 ) 103 104 func main() { 105 a0 = a 106 a0 = a1 107 a = a0 108 a = a1 // ERROR "cannot use" 109 a1 = a0 110 a1 = a // ERROR "cannot use" 111 112 b0 = b 113 b0 = b1 114 b = b0 115 b = b1 // ERROR "cannot use" 116 b1 = b0 117 b1 = b // ERROR "cannot use" 118 119 c0 = c 120 c0 = c1 121 c = c0 122 c = c1 // ERROR "cannot use" 123 c1 = c0 124 c1 = c // ERROR "cannot use" 125 126 f0 = f 127 f0 = f1 128 f = f0 129 f = f1 // ERROR "cannot use" 130 f1 = f0 131 f1 = f // ERROR "cannot use" 132 133 i0 = i 134 i0 = i1 135 i = i0 136 i = i1 137 i1 = i0 138 i1 = i 139 140 m0 = m 141 m0 = m1 142 m = m0 143 m = m1 // ERROR "cannot use" 144 m1 = m0 145 m1 = m // ERROR "cannot use" 146 147 p0 = p 148 p0 = p1 149 p = p0 150 p = p1 // ERROR "cannot use" 151 p1 = p0 152 p1 = p // ERROR "cannot use" 153 154 s0 = s 155 s0 = s1 156 s = s0 157 s = s1 // ERROR "cannot use" 158 s1 = s0 159 s1 = s // ERROR "cannot use" 160 161 pa0 = pa // ERROR "cannot use|incompatible" 162 pa0 = pa1 // ERROR "cannot use|incompatible" 163 pa = pa0 // ERROR "cannot use|incompatible" 164 pa = pa1 // ERROR "cannot use|incompatible" 165 pa1 = pa0 // ERROR "cannot use|incompatible" 166 pa1 = pa // ERROR "cannot use|incompatible" 167 168 pb0 = pb // ERROR "cannot use|incompatible" 169 pb0 = pb1 // ERROR "cannot use|incompatible" 170 pb = pb0 // ERROR "cannot use|incompatible" 171 pb = pb1 // ERROR "cannot use|incompatible" 172 pb1 = pb0 // ERROR "cannot use|incompatible" 173 pb1 = pb // ERROR "cannot use|incompatible" 174 175 pc0 = pc // ERROR "cannot use|incompatible" 176 pc0 = pc1 // ERROR "cannot use|incompatible" 177 pc = pc0 // ERROR "cannot use|incompatible" 178 pc = pc1 // ERROR "cannot use|incompatible" 179 pc1 = pc0 // ERROR "cannot use|incompatible" 180 pc1 = pc // ERROR "cannot use|incompatible" 181 182 pf0 = pf // ERROR "cannot use|incompatible" 183 pf0 = pf1 // ERROR "cannot use|incompatible" 184 pf = pf0 // ERROR "cannot use|incompatible" 185 pf = pf1 // ERROR "cannot use|incompatible" 186 pf1 = pf0 // ERROR "cannot use|incompatible" 187 pf1 = pf // ERROR "cannot use|incompatible" 188 189 pi0 = pi // ERROR "cannot use|incompatible" 190 pi0 = pi1 // ERROR "cannot use|incompatible" 191 pi = pi0 // ERROR "cannot use|incompatible" 192 pi = pi1 // ERROR "cannot use|incompatible" 193 pi1 = pi0 // ERROR "cannot use|incompatible" 194 pi1 = pi // ERROR "cannot use|incompatible" 195 196 pm0 = pm // ERROR "cannot use|incompatible" 197 pm0 = pm1 // ERROR "cannot use|incompatible" 198 pm = pm0 // ERROR "cannot use|incompatible" 199 pm = pm1 // ERROR "cannot use|incompatible" 200 pm1 = pm0 // ERROR "cannot use|incompatible" 201 pm1 = pm // ERROR "cannot use|incompatible" 202 203 pp0 = pp // ERROR "cannot use|incompatible" 204 pp0 = pp1 // ERROR "cannot use|incompatible" 205 pp = pp0 // ERROR "cannot use|incompatible" 206 pp = pp1 // ERROR "cannot use|incompatible" 207 pp1 = pp0 // ERROR "cannot use|incompatible" 208 pp1 = pp // ERROR "cannot use|incompatible" 209 210 ps0 = ps // ERROR "cannot use|incompatible" 211 ps0 = ps1 // ERROR "cannot use|incompatible" 212 ps = ps0 // ERROR "cannot use|incompatible" 213 ps = ps1 // ERROR "cannot use|incompatible" 214 ps1 = ps0 // ERROR "cannot use|incompatible" 215 ps1 = ps // ERROR "cannot use|incompatible" 216 217 218 a0 = [10]int(a) 219 a0 = [10]int(a1) 220 a = A(a0) 221 a = A(a1) 222 a1 = A1(a0) 223 a1 = A1(a) 224 225 b0 = []int(b) 226 b0 = []int(b1) 227 b = B(b0) 228 b = B(b1) 229 b1 = B1(b0) 230 b1 = B1(b) 231 232 c0 = chan int(c) 233 c0 = chan int(c1) 234 c = C(c0) 235 c = C(c1) 236 c1 = C1(c0) 237 c1 = C1(c) 238 239 f0 = func() int(f) 240 f0 = func() int(f1) 241 f = F(f0) 242 f = F(f1) 243 f1 = F1(f0) 244 f1 = F1(f) 245 246 i0 = interface { 247 m() int 248 }(i) 249 i0 = interface { 250 m() int 251 }(i1) 252 i = I(i0) 253 i = I(i1) 254 i1 = I1(i0) 255 i1 = I1(i) 256 257 m0 = map[int]int(m) 258 m0 = map[int]int(m1) 259 m = M(m0) 260 m = M(m1) 261 m1 = M1(m0) 262 m1 = M1(m) 263 264 p0 = (*int)(p) 265 p0 = (*int)(p1) 266 p = P(p0) 267 p = P(p1) 268 p1 = P1(p0) 269 p1 = P1(p) 270 271 s0 = struct { 272 X int 273 }(s) 274 s0 = struct { 275 X int 276 }(s1) 277 s = S(s0) 278 s = S(s1) 279 s1 = S1(s0) 280 s1 = S1(s) 281 282 pa0 = (*[10]int)(pa) 283 pa0 = (*[10]int)(pa1) 284 pa = (*A)(pa0) 285 pa = (*A)(pa1) 286 pa1 = (*A1)(pa0) 287 pa1 = (*A1)(pa) 288 289 pb0 = (*[]int)(pb) 290 pb0 = (*[]int)(pb1) 291 pb = (*B)(pb0) 292 pb = (*B)(pb1) 293 pb1 = (*B1)(pb0) 294 pb1 = (*B1)(pb) 295 296 pc0 = (*chan int)(pc) 297 pc0 = (*chan int)(pc1) 298 pc = (*C)(pc0) 299 pc = (*C)(pc1) 300 pc1 = (*C1)(pc0) 301 pc1 = (*C1)(pc) 302 303 pf0 = (*func() int)(pf) 304 pf0 = (*func() int)(pf1) 305 pf = (*F)(pf0) 306 pf = (*F)(pf1) 307 pf1 = (*F1)(pf0) 308 pf1 = (*F1)(pf) 309 310 pi0 = (*interface { 311 m() int 312 })(pi) 313 pi0 = (*interface { 314 m() int 315 })(pi1) 316 pi = (*I)(pi0) 317 pi = (*I)(pi1) 318 pi1 = (*I1)(pi0) 319 pi1 = (*I1)(pi) 320 321 pm0 = (*map[int]int)(pm) 322 pm0 = (*map[int]int)(pm1) 323 pm = (*M)(pm0) 324 pm = (*M)(pm1) 325 pm1 = (*M1)(pm0) 326 pm1 = (*M1)(pm) 327 328 pp0 = (**int)(pp) 329 pp0 = (**int)(pp1) 330 pp = (*P)(pp0) 331 pp = (*P)(pp1) 332 pp1 = (*P1)(pp0) 333 pp1 = (*P1)(pp) 334 335 ps0 = (*struct { 336 X int 337 })(ps) 338 ps0 = (*struct { 339 X int 340 })(ps1) 341 ps = (*S)(ps0) 342 ps = (*S)(ps1) 343 ps1 = (*S1)(ps0) 344 ps1 = (*S1)(ps) 345 346 }