Home | History | Annotate | Download | only in test
      1 // errorcheck
      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 
      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.
     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 {
     35 			continue L2 // ERROR "invalid continue label .*L2"
     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 {
     47 			continue L3 // ERROR "invalid continue label .*L3"
     48 		}
     49 		goto L3
     50 	}
     51 
     52 L4:
     53 	if true {
     54 		if x == 13 {
     55 			break L4 // ERROR "invalid break label .*L4"
     56 		}
     57 		if x == 14 {
     58 			continue L4 // ERROR "invalid continue label .*L4"
     59 		}
     60 		if x == 15 {
     61 			goto L4
     62 		}
     63 	}
     64 
     65 L5:
     66 	f()
     67 	if x == 16 {
     68 		break L5 // ERROR "invalid break label .*L5"
     69 	}
     70 	if x == 17 {
     71 		continue L5 // ERROR "invalid continue label .*L5"
     72 	}
     73 	if x == 18 {
     74 		goto L5
     75 	}
     76 
     77 	for {
     78 		if x == 19 {
     79 			break L1 // ERROR "invalid break label .*L1"
     80 		}
     81 		if x == 20 {
     82 			continue L1 // ERROR "invalid continue label .*L1"
     83 		}
     84 		if x == 21 {
     85 			goto L1
     86 		}
     87 	}
     88 }
     89