Source file test/fixedbugs/issue9608.dir/issue9608.go

     1  // Copyright 2015 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 main
     6  
     7  func fail() // unimplemented, to test dead code elimination
     8  
     9  // Test dead code elimination in if statements
    10  func init() {
    11  	if false {
    12  		fail()
    13  	}
    14  	if 0 == 1 {
    15  		fail()
    16  	}
    17  }
    18  
    19  // Test dead code elimination in ordinary switch statements
    20  func init() {
    21  	const x = 0
    22  	switch x {
    23  	case 1:
    24  		fail()
    25  	}
    26  
    27  	switch 1 {
    28  	case x:
    29  		fail()
    30  	}
    31  
    32  	switch {
    33  	case false:
    34  		fail()
    35  	}
    36  
    37  	const a = "a"
    38  	switch a {
    39  	case "b":
    40  		fail()
    41  	}
    42  
    43  	const snowman = '☃'
    44  	switch snowman {
    45  	case '☀':
    46  		fail()
    47  	}
    48  
    49  	const zero = float64(0.0)
    50  	const one = float64(1.0)
    51  	switch one {
    52  	case -1.0:
    53  		fail()
    54  	case zero:
    55  		fail()
    56  	}
    57  
    58  	switch 1.0i {
    59  	case 1:
    60  		fail()
    61  	case -1i:
    62  		fail()
    63  	}
    64  
    65  	const no = false
    66  	switch no {
    67  	case true:
    68  		fail()
    69  	}
    70  
    71  	// Test dead code elimination in large ranges.
    72  	switch 5 {
    73  	case 3, 4, 5, 6, 7:
    74  	case 0, 1, 2:
    75  		fail()
    76  	default:
    77  		fail()
    78  	}
    79  }
    80  
    81  func main() {
    82  }
    83  

View as plain text