summaryrefslogtreecommitdiff
path: root/libgo/go/go/types/testdata/labels.src
blob: 9f4240696549401a1813414e34887f0b36babb8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This file is a modified concatenation of the files
// $GOROOT/test/label.go and $GOROOT/test/label1.go.

package labels

var x int

func f0() {
L1 /* ERROR "label L1 declared but not used" */ :
	for {
	}
L2 /* ERROR "label L2 declared but not used" */ :
	select {
	}
L3 /* ERROR "label L3 declared but not used" */ :
	switch {
	}
L4 /* ERROR "label L4 declared but not used" */ :
	if true {
	}
L5 /* ERROR "label L5 declared but not used" */ :
	f0()
L6:
	f0()
L6 /* ERROR "label L6 already declared" */ :
	f0()
	if x == 20 {
		goto L6
	}

L7:
	for {
		break L7
		break L8 /* ERROR "invalid break label L8" */
	}

// A label must be directly associated with a switch, select, or
// for statement; it cannot be the label of a labeled statement.

L7a /* ERROR "declared but not used" */ : L7b:
	for {
		break L7a /* ERROR "invalid break label L7a" */
		continue L7a /* ERROR "invalid continue label L7a" */
		continue L7b
	}

L8:
	for {
		if x == 21 {
			continue L8
			continue L7 /* ERROR "invalid continue label L7" */
		}
	}

L9:
	switch {
	case true:
		break L9
	defalt /* ERROR "label defalt declared but not used" */ :
	}

L10:
	select {
	default:
		break L10
		break L9 /* ERROR "invalid break label L9" */
	}

	goto L10a
L10a: L10b:
	select {
	default:
		break L10a /* ERROR "invalid break label L10a" */
		break L10b
		continue L10b /* ERROR "invalid continue label L10b" */
	}
}

func f1() {
L1:
	for {
		if x == 0 {
			break L1
		}
		if x == 1 {
			continue L1
		}
		goto L1
	}

L2:
	select {
	default:
		if x == 0 {
			break L2
		}
		if x == 1 {
			continue L2 /* ERROR "invalid continue label L2" */
		}
		goto L2
	}

L3:
	switch {
	case x > 10:
		if x == 11 {
			break L3
		}
		if x == 12 {
			continue L3 /* ERROR "invalid continue label L3" */
		}
		goto L3
	}

L4:
	if true {
		if x == 13 {
			break L4 /* ERROR "invalid break label L4" */
		}
		if x == 14 {
			continue L4 /* ERROR "invalid continue label L4" */
		}
		if x == 15 {
			goto L4
		}
	}

L5:
	f1()
	if x == 16 {
		break L5 /* ERROR "invalid break label L5" */
	}
	if x == 17 {
		continue L5 /* ERROR "invalid continue label L5" */
	}
	if x == 18 {
		goto L5
	}

	for {
		if x == 19 {
			break L1 /* ERROR "invalid break label L1" */
		}
		if x == 20 {
			continue L1 /* ERROR "invalid continue label L1" */
		}
		if x == 21 {
			goto L1
		}
	}
}

// Additional tests not in the original files.

func f2() {
L1 /* ERROR "label L1 declared but not used" */ :
	if x == 0 {
		for {
			continue L1 /* ERROR "invalid continue label L1" */
		}
	}
}

func f3() {
L1:
L2:
L3:
	for {
		break L1 /* ERROR "invalid break label L1" */
		break L2 /* ERROR "invalid break label L2" */
		break L3
		continue L1 /* ERROR "invalid continue label L1" */
		continue L2 /* ERROR "invalid continue label L2" */
		continue L3
		goto L1
		goto L2
		goto L3
	}
}

// Blank labels are never declared.

func f4() {
_:
_: // multiple blank labels are ok
	goto _ /* ERROR "label _ not declared" */
}

func f5() {
_:
	for {
		break _ /* ERROR "invalid break label _" */
		continue _ /* ERROR "invalid continue label _" */
	}
}

func f6() {
_:
	switch {
	default:
		break _ /* ERROR "invalid break label _" */
	}
}