Russ Cox | d2cc988 | 2012-02-16 23:50:37 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 2 | |
| 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 Pike | 501f0b5 | 2012-02-23 18:47:26 +1100 | [diff] [blame] | 7 | |
| 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 Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 11 | |
| 12 | package main |
| 13 | |
| 14 | var x int |
| 15 | |
| 16 | func f() { |
| 17 | L1: |
| 18 | for { |
| 19 | if x == 0 { |
| 20 | break L1 |
| 21 | } |
| 22 | if x == 1 { |
| 23 | continue L1 |
| 24 | } |
| 25 | goto L1 |
| 26 | } |
| 27 | |
| 28 | L2: |
| 29 | select { |
| 30 | default: |
| 31 | if x == 0 { |
| 32 | break L2 |
| 33 | } |
| 34 | if x == 1 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 35 | continue L2 // ERROR "invalid continue label .*L2" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 36 | } |
| 37 | goto L2 |
| 38 | } |
| 39 | |
| 40 | L3: |
| 41 | switch { |
| 42 | case x > 10: |
| 43 | if x == 11 { |
| 44 | break L3 |
| 45 | } |
| 46 | if x == 12 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 47 | continue L3 // ERROR "invalid continue label .*L3" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 48 | } |
| 49 | goto L3 |
| 50 | } |
| 51 | |
| 52 | L4: |
| 53 | if true { |
| 54 | if x == 13 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 55 | break L4 // ERROR "invalid break label .*L4" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 56 | } |
| 57 | if x == 14 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 58 | continue L4 // ERROR "invalid continue label .*L4" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 59 | } |
| 60 | if x == 15 { |
| 61 | goto L4 |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | L5: |
| 66 | f() |
| 67 | if x == 16 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 68 | break L5 // ERROR "invalid break label .*L5" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 69 | } |
| 70 | if x == 17 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 71 | continue L5 // ERROR "invalid continue label .*L5" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 72 | } |
| 73 | if x == 18 { |
| 74 | goto L5 |
| 75 | } |
| 76 | |
| 77 | for { |
| 78 | if x == 19 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 79 | break L1 // ERROR "invalid break label .*L1" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 80 | } |
| 81 | if x == 20 { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 82 | continue L1 // ERROR "invalid continue label .*L1" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 83 | } |
| 84 | if x == 21 { |
| 85 | goto L1 |
| 86 | } |
| 87 | } |
| 88 | } |