Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 1 | // 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 | |
| 9 | package main |
| 10 | |
| 11 | func f1() int { return 1 } |
| 12 | func f2() (float, int) { return 1, 2 } |
| 13 | func f3() (float, int, string) { return 1, 2, "3" } |
| 14 | |
| 15 | func main() { |
| 16 | { |
| 17 | // simple redeclaration |
| 18 | i := f1(); |
Ian Lance Taylor | 8aa9161 | 2009-08-19 14:40:48 -0700 | [diff] [blame] | 19 | i := f1(); // ERROR "redeclared|no new" |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 20 | _ = i; |
Robert Griesemer | 0dd5be4 | 2009-04-20 15:23:21 -0700 | [diff] [blame] | 21 | } |
Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 22 | { |
| 23 | // change of type for f |
Ian Lance Taylor | 8aa9161 | 2009-08-19 14:40:48 -0700 | [diff] [blame] | 24 | i, f, s := f3(); |
| 25 | f, g, t := f3(); // ERROR "redeclared|cannot assign|incompatible" |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 26 | _, _, _, _, _ = i, f, s, g, t; |
Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 27 | } |
| 28 | { |
| 29 | // change of type for i |
Ian Lance Taylor | 8aa9161 | 2009-08-19 14:40:48 -0700 | [diff] [blame] | 30 | i, f, s := f3(); |
| 31 | j, i, t := f3(); // ERROR "redeclared|cannot assign|incompatible" |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 32 | _, _, _, _, _ = i, f, s, j, t; |
Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 33 | } |
| 34 | { |
| 35 | // no new variables |
| 36 | i, f, s := f3(); |
Ian Lance Taylor | 8aa9161 | 2009-08-19 14:40:48 -0700 | [diff] [blame] | 37 | i, f := f2(); // ERROR "redeclared|no new" |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 38 | _, _, _ = i, f, s; |
Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 39 | } |
| 40 | { |
| 41 | // single redeclaration |
Ian Lance Taylor | 8aa9161 | 2009-08-19 14:40:48 -0700 | [diff] [blame] | 42 | i, f, s := f3(); |
| 43 | i := f1(); // ERROR "redeclared|no new|incompatible" |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 44 | _, _, _ = i, f, s; |
Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 45 | } |
| 46 | // double redeclaration |
| 47 | { |
| 48 | i, f, s := f3(); |
Ian Lance Taylor | 8aa9161 | 2009-08-19 14:40:48 -0700 | [diff] [blame] | 49 | i, f := f2(); // ERROR "redeclared|no new" |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 50 | _, _, _ = i, f, s; |
Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 51 | } |
| 52 | { |
| 53 | // triple redeclaration |
| 54 | i, f, s := f3(); |
Ian Lance Taylor | 8aa9161 | 2009-08-19 14:40:48 -0700 | [diff] [blame] | 55 | i, f, s := f3(); // ERROR "redeclared|no new" |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 56 | _, _, _ = i, f, s; |
Rob Pike | 549a600 | 2009-04-18 17:21:00 -0700 | [diff] [blame] | 57 | } |
| 58 | } |