Home | History | Annotate | Download | only in fixedbugs
      1 // errorcheck
      2 
      3 // Copyright 2016 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 // Literals that happen to resolve to named constants
      8 // may be used as label names (see issue 13684). Make
      9 // sure that other literals don't crash the compiler.
     10 
     11 package main
     12 
     13 const labelname = 1
     14 
     15 func main() {
     16 	goto labelname
     17 labelname:
     18 }
     19 
     20 func f() {
     21 	var x int
     22 	switch x {
     23 	case 1:
     24 		2:	// ERROR "unexpected :"
     25 	case 2:
     26 	}
     27 
     28 	switch x {
     29 	case 1:
     30 		2: ;	// ERROR "unexpected :"
     31 	case 2:
     32 	}
     33 
     34 	var y string
     35 	switch y {
     36 	case "foo":
     37 		"bar":	// ERROR "unexpected :"
     38 	case "bar":
     39 	}
     40 
     41 	switch y {
     42 	case "foo":
     43 		"bar": ;	// ERROR "unexpected :"
     44 	case "bar":
     45 	}
     46 
     47 	var z bool
     48 	switch {
     49 	case z:
     50 		labelname:	// ERROR "missing statement after label"
     51 	case false:
     52 	}
     53 
     54 	switch {
     55 	case z:
     56 		labelname:
     57 	}
     58 
     59 	switch {
     60 	case z:
     61 		labelname: ;
     62 	case false:
     63 	}
     64 }