Skip to content

Commit d49572e

Browse files
test: add order of evaluation test case that gccgo got wrong
Updates #23188 Change-Id: Idc5567546d1c4c592f997a4cebbbf483b85331e0 Reviewed-on: https://go-review.googlesource.com/123115 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent eb9356b commit d49572e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/fixedbugs/issue23188.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// run
2+
3+
// Copyright 2018 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 order of evaluation of index operations.
8+
9+
package main
10+
11+
func main() {
12+
arr := []int{1, 2}
13+
14+
// The spec says that in an assignment statement the operands
15+
// of all index expressions and pointer indirections on the
16+
// left, and the expressions on the right, are evaluated in
17+
// the usual order. The usual order means function calls and
18+
// channel operations are done first. Then the assignments are
19+
// carried out one at a time. The operands of an index
20+
// expression include both the array and the index. So this
21+
// evaluates as
22+
// tmp1 := arr
23+
// tmp2 := len(arr) - 1
24+
// tmp3 := len(arr)
25+
// arr = arr[:tmp3-1]
26+
// tmp1[tmp2] = 3
27+
arr, arr[len(arr)-1] = arr[:len(arr)-1], 3
28+
29+
if len(arr) != 1 || arr[0] != 1 || arr[:2][1] != 3 {
30+
panic(arr)
31+
}
32+
}

0 commit comments

Comments
 (0)