blob: 9de01d43ea5e86a9885071b9fd441185762c17a3 [file] [log] [blame]
Russ Coxd2cc9882012-02-16 23:50:37 -05001// run
Russ Coxee9bfb02012-01-25 17:53:50 -05002
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07003// Copyright 2011 The Go Authors. All rights reserved.
Russ Coxee9bfb02012-01-25 17:53:50 -05004// 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
Todd Neale3e01222015-10-29 21:45:19 -050024//go:noinline
Russ Coxee9bfb02012-01-25 17:53:50 -050025func x() bool {
Russ Coxee9bfb02012-01-25 17:53:50 -050026 xy += "x"
27 return false
28}
29
Todd Neale3e01222015-10-29 21:45:19 -050030//go:noinline
Russ Coxee9bfb02012-01-25 17:53:50 -050031func y() string {
Russ Coxee9bfb02012-01-25 17:53:50 -050032 xy += "y"
33 return "abc"
34}
35
36func main() {
37 if f() == g() {
Alan Donovan052c9422013-02-12 13:17:49 -050038 panic("wrong f,g order")
Russ Coxee9bfb02012-01-25 17:53:50 -050039 }
40
41 if x() == (y() == "abc") {
42 panic("wrong compare")
43 }
44 if xy != "xy" {
Alan Donovan052c9422013-02-12 13:17:49 -050045 panic("wrong x,y order")
Russ Coxee9bfb02012-01-25 17:53:50 -050046 }
47}