Source file test/fixedbugs/issue14006.go

     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 :|expected .*;.* or .*}.* or newline|value computed is not used"
    25  	case 2:
    26  	}
    27  
    28  	switch x {
    29  	case 1:
    30  		2: ;	// ERROR "unexpected :|expected .*;.* or .*}.* or newline|value computed is not used"
    31  	case 2:
    32  	}
    33  
    34  	var y string
    35  	switch y {
    36  	case "foo":
    37  		"bar":	// ERROR "unexpected :|expected .*;.* or .*}.* or newline|value computed is not used"
    38  	case "bar":
    39  	}
    40  
    41  	switch y {
    42  	case "foo":
    43  		"bar": ;	// ERROR "unexpected :|expected .*;.* or .*}.* or newline|value computed is not used"
    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  
    55  func g() {
    56  	var z bool
    57  	switch {
    58  	case z:
    59  		labelname:	// ERROR "label labelname defined and not used|previous definition|defined and not used"
    60  	}
    61  
    62  	switch {
    63  	case z:
    64  		labelname: ;	// ERROR "label labelname already defined at LINE-5|label .*labelname.* already defined"
    65  	case false:
    66  	}
    67  }
    68  

View as plain text