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 | // Verify that erroneous labels are caught by the compiler. |
| 8 | // This set is caught by pass 1. |
| 9 | // Does not compile. |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 10 | |
| 11 | package main |
| 12 | |
| 13 | var x int |
| 14 | |
| 15 | func f() { |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 16 | L1: // ERROR "label .*L1.* defined and not used" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 17 | for { |
| 18 | } |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 19 | L2: // ERROR "label .*L2.* defined and not used" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 20 | select {} |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 21 | L3: // ERROR "label .*L3.* defined and not used" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 22 | switch { |
| 23 | } |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 24 | L4: // ERROR "label .*L4.* defined and not used" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 25 | if true { |
| 26 | } |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 27 | L5: // ERROR "label .*L5.* defined and not used" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 28 | f() |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 29 | L6: // GCCGO_ERROR "previous" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 30 | f() |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 31 | L6: // ERROR "label .*L6.* already defined" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 32 | f() |
| 33 | if x == 20 { |
| 34 | goto L6 |
| 35 | } |
| 36 | |
| 37 | L7: |
| 38 | for { |
| 39 | break L7 |
| 40 | } |
| 41 | |
| 42 | L8: |
| 43 | for { |
| 44 | if x == 21 { |
| 45 | continue L8 |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | L9: |
| 50 | switch { |
| 51 | case true: |
| 52 | break L9 |
Ian Lance Taylor | 8beb4be | 2011-03-25 10:36:46 -0700 | [diff] [blame] | 53 | defalt: // ERROR "label .*defalt.* defined and not used" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | L10: |
| 57 | select { |
| 58 | default: |
| 59 | break L10 |
| 60 | } |
Josh Bleecher Snyder | 61aa095 | 2015-07-20 15:39:14 -0700 | [diff] [blame] | 61 | |
| 62 | goto L10 |
| 63 | |
| 64 | goto go2 // ERROR "label go2 not defined" |
Russ Cox | 66f09fd | 2011-03-15 14:05:37 -0400 | [diff] [blame] | 65 | } |