blob: 3b22199f7e3b7515a058d0557268f1cccb8414f3 [file] [log] [blame]
Russ Coxd2cc9882012-02-16 23:50:37 -05001// run
Russ Coxbac8f182011-04-26 00:57:03 -04002
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07003// Copyright 2011 The Go Authors. All rights reserved.
Russ Coxbac8f182011-04-26 00:57:03 -04004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
Rob Pike83976e32012-02-19 14:28:53 +11007// Test evaluation order in if condition.
8
Russ Coxbac8f182011-04-26 00:57:03 -04009package main
10
11var calledf = false
12
13func f() int {
14 calledf = true
15 return 1
16}
17
18func g() int {
19 if !calledf {
Alan Donovan052c9422013-02-12 13:17:49 -050020 panic("BUG: func7 - called g before f")
Russ Coxbac8f182011-04-26 00:57:03 -040021 }
22 return 0
23}
24
25func main() {
Aaron Jacobs86286882015-06-24 09:50:12 +100026 // gc used to evaluate g() before f().
Russ Coxbac8f182011-04-26 00:57:03 -040027 if f() < g() {
28 panic("wrong answer")
29 }
30}