blob: 5e5e145011040dc7f974012b20e4db67a378c133 [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
Russ Coxf2b5a072011-01-19 23:09:00 -050011func f1() int { return 1 }
12func f2() (float32, int) { return 1, 2 }
13func f3() (float32, int, string) { return 1, 2, "3" }
Rob Pike549a6002009-04-18 17:21:00 -070014
15func main() {
16 {
17 // simple redeclaration
Rob Pike4f61fc92010-09-04 10:36:13 +100018 i := f1()
Russ Coxf2b5a072011-01-19 23:09:00 -050019 i := f1() // ERROR "redeclared|no new"
Rob Pike4f61fc92010-09-04 10:36:13 +100020 _ = i
Robert Griesemer0dd5be42009-04-20 15:23:21 -070021 }
Rob Pike549a6002009-04-18 17:21:00 -070022 {
23 // change of type for f
Rob Pike4f61fc92010-09-04 10:36:13 +100024 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050025 f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible"
Rob Pike4f61fc92010-09-04 10:36:13 +100026 _, _, _, _, _ = i, f, s, g, t
Rob Pike549a6002009-04-18 17:21:00 -070027 }
28 {
29 // change of type for i
Rob Pike4f61fc92010-09-04 10:36:13 +100030 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050031 j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible"
Rob Pike4f61fc92010-09-04 10:36:13 +100032 _, _, _, _, _ = i, f, s, j, t
Rob Pike549a6002009-04-18 17:21:00 -070033 }
34 {
35 // no new variables
Rob Pike4f61fc92010-09-04 10:36:13 +100036 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050037 i, f := f2() // ERROR "redeclared|no new"
Rob Pike4f61fc92010-09-04 10:36:13 +100038 _, _, _ = i, f, s
Rob Pike549a6002009-04-18 17:21:00 -070039 }
40 {
41 // single redeclaration
Rob Pike4f61fc92010-09-04 10:36:13 +100042 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050043 i := f1() // ERROR "redeclared|no new|incompatible"
Rob Pike4f61fc92010-09-04 10:36:13 +100044 _, _, _ = i, f, s
Rob Pike549a6002009-04-18 17:21:00 -070045 }
Russ Coxf2b5a072011-01-19 23:09:00 -050046 // double redeclaration
Rob Pike549a6002009-04-18 17:21:00 -070047 {
Rob Pike4f61fc92010-09-04 10:36:13 +100048 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050049 i, f := f2() // ERROR "redeclared|no new"
Rob Pike4f61fc92010-09-04 10:36:13 +100050 _, _, _ = i, f, s
Rob Pike549a6002009-04-18 17:21:00 -070051 }
52 {
53 // triple redeclaration
Rob Pike4f61fc92010-09-04 10:36:13 +100054 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050055 i, f, s := f3() // ERROR "redeclared|no new"
Rob Pike4f61fc92010-09-04 10:36:13 +100056 _, _, _ = i, f, s
Rob Pike549a6002009-04-18 17:21:00 -070057 }
58}