~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to test/declbad.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-04-20 17:36:48 UTC
  • Revision ID: james.westby@ubuntu.com-20110420173648-ifergoxyrm832trd
Tags: upstream-2011.03.07.1
Import upstream version 2011.03.07.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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() (float32, int)         { return 1, 2 }
 
13
func f3() (float32, int, string) { return 1, 2, "3" }
 
14
 
 
15
func main() {
 
16
        {
 
17
                // simple redeclaration
 
18
                i := f1()
 
19
                i := f1() // ERROR "redeclared|no new"
 
20
                _ = i
 
21
        }
 
22
        {
 
23
                // change of type for f
 
24
                i, f, s := f3()
 
25
                f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible"
 
26
                _, _, _, _, _ = i, f, s, g, t
 
27
        }
 
28
        {
 
29
                // change of type for i
 
30
                i, f, s := f3()
 
31
                j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible"
 
32
                _, _, _, _, _ = i, f, s, j, t
 
33
        }
 
34
        {
 
35
                // no new variables
 
36
                i, f, s := f3()
 
37
                i, f := f2() // ERROR "redeclared|no new"
 
38
                _, _, _ = i, f, s
 
39
        }
 
40
        {
 
41
                // single redeclaration
 
42
                i, f, s := f3()
 
43
                i := f1() // ERROR "redeclared|no new|incompatible"
 
44
                _, _, _ = i, f, s
 
45
        }
 
46
        // double redeclaration
 
47
        {
 
48
                i, f, s := f3()
 
49
                i, f := f2() // ERROR "redeclared|no new"
 
50
                _, _, _ = i, f, s
 
51
        }
 
52
        {
 
53
                // triple redeclaration
 
54
                i, f, s := f3()
 
55
                i, f, s := f3() // ERROR "redeclared|no new"
 
56
                _, _, _ = i, f, s
 
57
        }
 
58
}