blob: 5fbb04ab5de263d973937e9a33c06773ff71d074 [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 Taylor8aa91612009-08-19 14:40:48 -070019 i := f1(); // ERROR "redeclared|no new"
Russ Coxae54cf72009-09-15 12:42:24 -070020 _ = i;
Robert Griesemer0dd5be42009-04-20 15:23:21 -070021 }
Rob Pike549a6002009-04-18 17:21:00 -070022 {
23 // change of type for f
Ian Lance Taylor8aa91612009-08-19 14:40:48 -070024 i, f, s := f3();
25 f, g, t := f3(); // ERROR "redeclared|cannot assign|incompatible"
Russ Coxae54cf72009-09-15 12:42:24 -070026 _, _, _, _, _ = i, f, s, g, t;
Rob Pike549a6002009-04-18 17:21:00 -070027 }
28 {
29 // change of type for i
Ian Lance Taylor8aa91612009-08-19 14:40:48 -070030 i, f, s := f3();
31 j, i, t := f3(); // ERROR "redeclared|cannot assign|incompatible"
Russ Coxae54cf72009-09-15 12:42:24 -070032 _, _, _, _, _ = i, f, s, j, t;
Rob Pike549a6002009-04-18 17:21:00 -070033 }
34 {
35 // no new variables
36 i, f, s := f3();
Ian Lance Taylor8aa91612009-08-19 14:40:48 -070037 i, f := f2(); // ERROR "redeclared|no new"
Russ Coxae54cf72009-09-15 12:42:24 -070038 _, _, _ = i, f, s;
Rob Pike549a6002009-04-18 17:21:00 -070039 }
40 {
41 // single redeclaration
Ian Lance Taylor8aa91612009-08-19 14:40:48 -070042 i, f, s := f3();
43 i := f1(); // ERROR "redeclared|no new|incompatible"
Russ Coxae54cf72009-09-15 12:42:24 -070044 _, _, _ = i, f, s;
Rob Pike549a6002009-04-18 17:21:00 -070045 }
46 // double redeclaration
47 {
48 i, f, s := f3();
Ian Lance Taylor8aa91612009-08-19 14:40:48 -070049 i, f := f2(); // ERROR "redeclared|no new"
Russ Coxae54cf72009-09-15 12:42:24 -070050 _, _, _ = i, f, s;
Rob Pike549a6002009-04-18 17:21:00 -070051 }
52 {
53 // triple redeclaration
54 i, f, s := f3();
Ian Lance Taylor8aa91612009-08-19 14:40:48 -070055 i, f, s := f3(); // ERROR "redeclared|no new"
Russ Coxae54cf72009-09-15 12:42:24 -070056 _, _, _ = i, f, s;
Rob Pike549a6002009-04-18 17:21:00 -070057 }
58}