blob: f923a18820e329c386de32949406b7db957de289 [file] [log] [blame]
Russ Coxd2cc9882012-02-16 23:50:37 -05001// errorcheck
Russ Cox66f09fd2011-03-15 14:05:37 -04002
3// Copyright 2011 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
Rob Pike501f0b52012-02-23 18:47:26 +11007
8// Verify that erroneous labels are caught by the compiler.
9// This set is caught by pass 2. That's why this file is label1.go.
10// Does not compile.
Russ Cox66f09fd2011-03-15 14:05:37 -040011
12package main
13
14var x int
15
16func f() {
17L1:
18 for {
19 if x == 0 {
20 break L1
21 }
22 if x == 1 {
23 continue L1
24 }
25 goto L1
26 }
27
28L2:
29 select {
30 default:
31 if x == 0 {
32 break L2
33 }
34 if x == 1 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070035 continue L2 // ERROR "invalid continue label .*L2"
Russ Cox66f09fd2011-03-15 14:05:37 -040036 }
37 goto L2
38 }
39
40L3:
41 switch {
42 case x > 10:
43 if x == 11 {
44 break L3
45 }
46 if x == 12 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070047 continue L3 // ERROR "invalid continue label .*L3"
Russ Cox66f09fd2011-03-15 14:05:37 -040048 }
49 goto L3
50 }
51
52L4:
53 if true {
54 if x == 13 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070055 break L4 // ERROR "invalid break label .*L4"
Russ Cox66f09fd2011-03-15 14:05:37 -040056 }
57 if x == 14 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070058 continue L4 // ERROR "invalid continue label .*L4"
Russ Cox66f09fd2011-03-15 14:05:37 -040059 }
60 if x == 15 {
61 goto L4
62 }
63 }
64
65L5:
66 f()
67 if x == 16 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070068 break L5 // ERROR "invalid break label .*L5"
Russ Cox66f09fd2011-03-15 14:05:37 -040069 }
70 if x == 17 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070071 continue L5 // ERROR "invalid continue label .*L5"
Russ Cox66f09fd2011-03-15 14:05:37 -040072 }
73 if x == 18 {
74 goto L5
75 }
76
77 for {
78 if x == 19 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070079 break L1 // ERROR "invalid break label .*L1"
Russ Cox66f09fd2011-03-15 14:05:37 -040080 }
81 if x == 20 {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070082 continue L1 // ERROR "invalid continue label .*L1"
Russ Cox66f09fd2011-03-15 14:05:37 -040083 }
84 if x == 21 {
85 goto L1
86 }
87 }
88}