Source file src/cmd/compile/internal/syntax/testdata/fallthrough.go

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package fallthroughs
     6  
     7  func _() {
     8  	var x int
     9  	switch x {
    10  	case 0:
    11  		fallthrough
    12  
    13  	case 1:
    14  		fallthrough // ERROR fallthrough statement out of place
    15  		{
    16  		}
    17  
    18  	case 2:
    19  		{
    20  			fallthrough // ERROR fallthrough statement out of place
    21  		}
    22  
    23  	case 3:
    24  		for {
    25  			fallthrough // ERROR fallthrough statement out of place
    26  		}
    27  
    28  	case 4:
    29  		fallthrough // trailing empty statements are ok
    30  		;
    31  		;
    32  
    33  	case 5:
    34  		fallthrough
    35  
    36  	default:
    37  		fallthrough // ERROR cannot fallthrough final case in switch
    38  	}
    39  
    40  	fallthrough // ERROR fallthrough statement out of place
    41  
    42  	if true {
    43  		fallthrough // ERROR fallthrough statement out of place
    44  	}
    45  
    46  	for {
    47  		fallthrough // ERROR fallthrough statement out of place
    48  	}
    49  
    50  	var t any
    51  	switch t.(type) {
    52  	case int:
    53  		fallthrough // ERROR cannot fallthrough in type switch
    54  	}
    55  }
    56  

View as plain text