blob: c3c0c27edd263b87a3d2477b6ce6014833d9c816 [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// Verify that erroneous labels are caught by the compiler.
8// This set is caught by pass 1.
9// Does not compile.
Russ Cox66f09fd2011-03-15 14:05:37 -040010
11package main
12
13var x int
14
15func f() {
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070016L1: // ERROR "label .*L1.* defined and not used"
Russ Cox66f09fd2011-03-15 14:05:37 -040017 for {
18 }
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070019L2: // ERROR "label .*L2.* defined and not used"
Josh Bleecher Snyderffbf2092015-07-20 13:00:28 -070020 select {}
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070021L3: // ERROR "label .*L3.* defined and not used"
Russ Cox66f09fd2011-03-15 14:05:37 -040022 switch {
23 }
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070024L4: // ERROR "label .*L4.* defined and not used"
Russ Cox66f09fd2011-03-15 14:05:37 -040025 if true {
26 }
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070027L5: // ERROR "label .*L5.* defined and not used"
Russ Cox66f09fd2011-03-15 14:05:37 -040028 f()
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070029L6: // GCCGO_ERROR "previous"
Russ Cox66f09fd2011-03-15 14:05:37 -040030 f()
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070031L6: // ERROR "label .*L6.* already defined"
Russ Cox66f09fd2011-03-15 14:05:37 -040032 f()
33 if x == 20 {
34 goto L6
35 }
36
37L7:
38 for {
39 break L7
40 }
41
42L8:
43 for {
44 if x == 21 {
45 continue L8
46 }
47 }
48
49L9:
50 switch {
51 case true:
52 break L9
Ian Lance Taylor8beb4be2011-03-25 10:36:46 -070053 defalt: // ERROR "label .*defalt.* defined and not used"
Russ Cox66f09fd2011-03-15 14:05:37 -040054 }
55
56L10:
57 select {
58 default:
59 break L10
60 }
Josh Bleecher Snyder61aa0952015-07-20 15:39:14 -070061
62 goto L10
63
64 goto go2 // ERROR "label go2 not defined"
Russ Cox66f09fd2011-03-15 14:05:37 -040065}