blob: 7f6e56d7e44e42ee9ff54fbd9e08446681c01565 [file] [log] [blame]
Rob Pike549a6002009-04-18 17:21:00 -07001// errchk $G -e $F.go
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// Incorrect short declarations and redeclarations.
8
9package main
10
11func f1() int { return 1 }
12func f2() (float, int) { return 1, 2 }
13func f3() (float, int, string) { return 1, 2, "3" }
14
15func main() {
16 {
17 // simple redeclaration
18 i := f1();
Ian Lance Taylor905338a2009-04-28 07:16:03 -070019 i := f1(); // ERROR "redeclared|redefinition"
Robert Griesemer0dd5be42009-04-20 15:23:21 -070020 }
Rob Pike549a6002009-04-18 17:21:00 -070021 {
22 // change of type for f
Ian Lance Taylor905338a2009-04-28 07:16:03 -070023 i, f, s := f3(); // GCCGO_ERROR "previous"
24 f, g, t := f3(); // ERROR "redeclared|redefinition"
Rob Pike549a6002009-04-18 17:21:00 -070025 }
26 {
27 // change of type for i
Ian Lance Taylor905338a2009-04-28 07:16:03 -070028 i, f, s := f3(); // GCCGO_ERROR "previous"
29 j, i, t := f3(); // ERROR "redeclared|redefinition"
Rob Pike549a6002009-04-18 17:21:00 -070030 }
31 {
32 // no new variables
33 i, f, s := f3();
Ian Lance Taylor905338a2009-04-28 07:16:03 -070034 i, f := f2(); // ERROR "redeclared|redefinition"
Rob Pike549a6002009-04-18 17:21:00 -070035 }
36 {
37 // single redeclaration
Ian Lance Taylor905338a2009-04-28 07:16:03 -070038 i, f, s := f3(); // GCCGO_ERROR "previous"
39 i := f1(); // ERROR "redeclared|redefinition"
Rob Pike549a6002009-04-18 17:21:00 -070040 }
41 // double redeclaration
42 {
43 i, f, s := f3();
Ian Lance Taylor905338a2009-04-28 07:16:03 -070044 i, f := f2(); // ERROR "redeclared|redefinition"
Rob Pike549a6002009-04-18 17:21:00 -070045 }
46 {
47 // triple redeclaration
48 i, f, s := f3();
Ian Lance Taylor905338a2009-04-28 07:16:03 -070049 i, f, s := f3(); // ERROR "redeclared|redefinition"
Rob Pike549a6002009-04-18 17:21:00 -070050 }
51}