]> Cypherpunks.ru repositories - gostls13.git/blob - test/declbad.go
test: match gccgo error messages
[gostls13.git] / test / declbad.go
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() { // ERROR "redeclared|no new|incompatible"
45                 }
46                 _ = i
47         }
48         {
49                 // single redeclaration
50                 i, f, s := f3()
51                 i := 1 // ERROR "redeclared|no new|incompatible"
52                 _, _, _ = i, f, s
53         }
54         // double redeclaration
55         {
56                 i, f, s := f3()
57                 i, f := f2() // ERROR "redeclared|no new"
58                 _, _, _ = i, f, s
59         }
60         {
61                 // triple redeclaration
62                 i, f, s := f3()
63                 i, f, s := f3() // ERROR "redeclared|no new"
64                 _, _, _ = i, f, s
65         }
66 }