github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/func7.go (about)

     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 in if condition.
     8  
     9  package main
    10  
    11  var calledf = false
    12  
    13  func f() int {
    14  	calledf = true
    15  	return 1
    16  }
    17  
    18  func g() int {
    19  	if !calledf {
    20  		panic("BUG: func7 - called g before f")
    21  	}
    22  	return 0
    23  }
    24  
    25  func main() {
    26  	// 6g, 8g, 5g all used to evaluate g() before f().
    27  	if f() < g() {
    28  		panic("wrong answer")
    29  	}
    30  }