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