blob: 95b6346c3edfa9188d0889b0c091279793c55ce9 [file] [log] [blame]
Rob Pike549a6002009-04-18 17:21:00 -07001// $G $F.go && $L $F.$A && ./$A.out
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// Correct 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
Rob Pikef83f2452009-04-19 21:12:13 -070015func x() (s string) {
Rob Pike4f61fc92010-09-04 10:36:13 +100016 a, b, s := f3()
17 _, _ = a, b
Russ Coxf2b5a072011-01-19 23:09:00 -050018 return // tests that result var is in scope for redeclaration
Rob Pikef83f2452009-04-19 21:12:13 -070019}
20
Rob Pike549a6002009-04-18 17:21:00 -070021func main() {
Rob Pike4f61fc92010-09-04 10:36:13 +100022 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050023 j, f := f2() // redeclare f
Rob Pike4f61fc92010-09-04 10:36:13 +100024 k := f1()
25 m, g, s := f3()
26 m, h, s := f3()
Rob Pike549a6002009-04-18 17:21:00 -070027 {
28 // new block should be ok.
Rob Pike4f61fc92010-09-04 10:36:13 +100029 i, f, s := f3()
Russ Coxf2b5a072011-01-19 23:09:00 -050030 j, f := f2() // redeclare f
Rob Pike4f61fc92010-09-04 10:36:13 +100031 k := f1()
32 m, g, s := f3()
33 m, h, s := f3()
34 _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
Rob Pike549a6002009-04-18 17:21:00 -070035 }
Rob Pikef83f2452009-04-19 21:12:13 -070036 if x() != "3" {
Rob Pike4f61fc92010-09-04 10:36:13 +100037 println("x() failed")
Rob Pikef83f2452009-04-19 21:12:13 -070038 }
Rob Pike4f61fc92010-09-04 10:36:13 +100039 _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
Rob Pike549a6002009-04-18 17:21:00 -070040}