2012-02-17 04:50:37 +00:00
|
|
|
// errorcheck
|
2011-03-15 18:05:37 +00:00
|
|
|
|
2016-04-10 21:32:26 +00:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
2011-03-15 18:05:37 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-02-23 07:47:26 +00:00
|
|
|
// Verify that erroneous labels are caught by the compiler.
|
|
|
|
// This set is caught by pass 2. That's why this file is label1.go.
|
|
|
|
// Does not compile.
|
2011-03-15 18:05:37 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
var x int
|
|
|
|
|
2017-04-11 19:31:41 +00:00
|
|
|
func f1() {
|
|
|
|
switch x {
|
|
|
|
case 1:
|
|
|
|
continue // ERROR "continue is not in a loop$"
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
default:
|
|
|
|
continue // ERROR "continue is not in a loop$"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func f2() {
|
2011-03-15 18:05:37 +00:00
|
|
|
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 {
|
2017-04-11 19:31:41 +00:00
|
|
|
continue L2 // ERROR "invalid continue label .*L2|continue is not in a loop$"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
goto L2
|
|
|
|
}
|
|
|
|
|
2015-07-20 22:39:14 +00:00
|
|
|
for {
|
|
|
|
if x == 1 {
|
|
|
|
continue L2 // ERROR "invalid continue label .*L2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-15 18:05:37 +00:00
|
|
|
L3:
|
|
|
|
switch {
|
|
|
|
case x > 10:
|
|
|
|
if x == 11 {
|
|
|
|
break L3
|
|
|
|
}
|
|
|
|
if x == 12 {
|
2017-04-11 19:31:41 +00:00
|
|
|
continue L3 // ERROR "invalid continue label .*L3|continue is not in a loop$"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
goto L3
|
|
|
|
}
|
|
|
|
|
|
|
|
L4:
|
|
|
|
if true {
|
|
|
|
if x == 13 {
|
2011-03-25 17:36:46 +00:00
|
|
|
break L4 // ERROR "invalid break label .*L4"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
if x == 14 {
|
2017-04-11 19:31:41 +00:00
|
|
|
continue L4 // ERROR "invalid continue label .*L4|continue is not in a loop$"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
if x == 15 {
|
|
|
|
goto L4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
L5:
|
2017-04-11 19:31:41 +00:00
|
|
|
f2()
|
2011-03-15 18:05:37 +00:00
|
|
|
if x == 16 {
|
2011-03-25 17:36:46 +00:00
|
|
|
break L5 // ERROR "invalid break label .*L5"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
if x == 17 {
|
2017-04-11 19:31:41 +00:00
|
|
|
continue L5 // ERROR "invalid continue label .*L5|continue is not in a loop$"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
if x == 18 {
|
|
|
|
goto L5
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
if x == 19 {
|
2011-03-25 17:36:46 +00:00
|
|
|
break L1 // ERROR "invalid break label .*L1"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
if x == 20 {
|
2011-03-25 17:36:46 +00:00
|
|
|
continue L1 // ERROR "invalid continue label .*L1"
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|
|
|
|
if x == 21 {
|
|
|
|
goto L1
|
|
|
|
}
|
|
|
|
}
|
2015-07-20 22:39:14 +00:00
|
|
|
|
2017-04-11 19:31:41 +00:00
|
|
|
continue // ERROR "continue is not in a loop$"
|
2015-07-20 22:39:14 +00:00
|
|
|
for {
|
|
|
|
continue on // ERROR "continue label not defined: on"
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:31:41 +00:00
|
|
|
break // ERROR "break is not in a loop, switch, or select"
|
2015-07-20 22:39:14 +00:00
|
|
|
for {
|
|
|
|
break dance // ERROR "break label not defined: dance"
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
switch x {
|
|
|
|
case 1:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2011-03-15 18:05:37 +00:00
|
|
|
}
|