2018-01-24 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / go.test / test / declbad.go
blob728eceb7f1e6b9cd755def6ae347d34724eee1a0
1 // errorcheck
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.
7 // Test that incorrect short declarations and redeclarations are detected.
8 // Does not compile.
10 package main
12 func f1() int { return 1 }
13 func f2() (float32, int) { return 1, 2 }
14 func f3() (float32, int, string) { return 1, 2, "3" }
16 func main() {
18 // simple redeclaration
19 i := f1()
20 i := f1() // ERROR "redeclared|no new"
21 _ = i
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
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
36 // no new variables
37 i, f, s := f3()
38 i, f := f2() // ERROR "redeclared|no new"
39 _, _, _ = i, f, s
42 // multiline no new variables
43 i := f1
44 i := func() int { // ERROR "redeclared|no new|incompatible"
45 return 0
47 _ = i
50 // single redeclaration
51 i, f, s := f3()
52 i := 1 // ERROR "redeclared|no new|incompatible"
53 _, _, _ = i, f, s
55 // double redeclaration
57 i, f, s := f3()
58 i, f := f2() // ERROR "redeclared|no new"
59 _, _, _ = i, f, s
62 // triple redeclaration
63 i, f, s := f3()
64 i, f, s := f3() // ERROR "redeclared|no new"
65 _, _, _ = i, f, s