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 // Test that incorrect short declarations and redeclarations are detected. 8 // Does not compile. 9 10 package main 11 12 func f1() int { return 1 } 13 func f2() (float32, int) { return 1, 2 } 14 func f3() (float32, int, string) { return 1, 2, "3" } 15 16 func main() { 17 { 18 // simple redeclaration 19 i := f1() 20 i := f1() // ERROR "redeclared|no new" 21 _ = i 22 } 23 { 24 // change of type for f 25 i, f, s := f3() 26 f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible" 27 _, _, _, _, _ = i, f, s, g, t 28 } 29 { 30 // change of type for i 31 i, f, s := f3() 32 j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible" 33 _, _, _, _, _ = i, f, s, j, t 34 } 35 { 36 // no new variables 37 i, f, s := f3() 38 i, f := f2() // ERROR "redeclared|no new" 39 _, _, _ = i, f, s 40 } 41 { 42 // multiline no new variables 43 i := f1 44 i := func() int { // ERROR "redeclared|no new|incompatible" 45 return 0 46 } 47 _ = i 48 } 49 { 50 // single redeclaration 51 i, f, s := f3() 52 i := 1 // ERROR "redeclared|no new|incompatible" 53 _, _, _ = i, f, s 54 } 55 // double redeclaration 56 { 57 i, f, s := f3() 58 i, f := f2() // ERROR "redeclared|no new" 59 _, _, _ = i, f, s 60 } 61 { 62 // triple redeclaration 63 i, f, s := f3() 64 i, f, s := f3() // ERROR "redeclared|no new" 65 _, _, _ = i, f, s 66 } 67 } 68