blob: 13051802ecdcdae043aad275a7096b85297263bd [file] [log] [blame]
Russ Coxd2cc9882012-02-16 23:50:37 -05001// run
Russ Coxee9bfb02012-01-25 17:53:50 -05002
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
Rob Pike83976e32012-02-19 14:28:53 +11007// Test evaluation order.
8
Russ Coxee9bfb02012-01-25 17:53:50 -05009package main
10
11var calledf int
12
13func f() int {
14 calledf++
15 return 0
16}
17
18func g() int {
19 return calledf
20}
21
22var xy string
23
24func x() bool {
25 for false {
26 } // no inlining
27 xy += "x"
28 return false
29}
30
31func y() string {
32 for false {
33 } // no inlining
34 xy += "y"
35 return "abc"
36}
37
38func main() {
39 if f() == g() {
Alan Donovan052c9422013-02-12 13:17:49 -050040 panic("wrong f,g order")
Russ Coxee9bfb02012-01-25 17:53:50 -050041 }
42
43 if x() == (y() == "abc") {
44 panic("wrong compare")
45 }
46 if xy != "xy" {
Alan Donovan052c9422013-02-12 13:17:49 -050047 panic("wrong x,y order")
Russ Coxee9bfb02012-01-25 17:53:50 -050048 }
49}