Source file test/func8.go

     1  // run
     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  // Test evaluation order.
     8  
     9  package main
    10  
    11  var calledf int
    12  
    13  func f() int {
    14  	calledf++
    15  	return 0
    16  }
    17  
    18  func g() int {
    19  	return calledf
    20  }
    21  
    22  var xy string
    23  
    24  //go:noinline
    25  func x() bool {
    26  	xy += "x"
    27  	return false
    28  }
    29  
    30  //go:noinline
    31  func y() string {
    32  	xy += "y"
    33  	return "abc"
    34  }
    35  
    36  func main() {
    37  	if f() == g() {
    38  		panic("wrong f,g order")
    39  	}
    40  
    41  	if x() == (y() == "abc") {
    42  		panic("wrong compare")
    43  	}
    44  	if xy != "xy" {
    45  		panic("wrong x,y order")
    46  	}
    47  }
    48  

View as plain text