diff options
author | Dhananjay Nakrani <dhananjaynakrani@gmail.com> | 2016-12-23 22:28:45 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2017-02-11 21:46:21 +0000 |
commit | 1cde87b312c5687cd0d70457c48586055e8c53ca (patch) | |
tree | 108ff1267dbfffb9a212b8f97400a693e4e8358b /test/reorder.go | |
parent | e0d50a5830cbd17810cd488bf70d86fd0c2757ec (diff) | |
download | go-1cde87b312c5687cd0d70457c48586055e8c53ca.tar.gz go-1cde87b312c5687cd0d70457c48586055e8c53ca.zip |
cmd/compile: Ensure left-to-right assignment
Add temporaries to reorder the assignment for OAS2XXX nodes.
This makes orderstmt(), rewrite
a, b, c = ...
as
tmp1, tmp2, tmp3 = ...
a, b, c = tmp1, tmp2, tmp3
and
a, ok = ...
as
t1, t2 = ...
a = t1
ok = t2
Fixes #13433.
Change-Id: Id0f5956e3a254d0a6f4b89b5f7b0e055b1f0e21f
Reviewed-on: https://go-review.googlesource.com/34713
Run-TryBot: Dhananjay Nakrani <dhananjayn@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/reorder.go')
-rw-r--r-- | test/reorder.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/reorder.go b/test/reorder.go index fc44be90de..3a87d025c2 100644 --- a/test/reorder.go +++ b/test/reorder.go @@ -19,6 +19,7 @@ func main() { p6() p7() p8() + p9() } var gx []int @@ -112,3 +113,39 @@ func p8() { panic(m[0]) } } + +// Issue #13433: Left-to-right assignment of OAS2XXX nodes. +func p9() { + var x bool + + // OAS2FUNC + x, x = fn() + checkOAS2XXX(x, "x, x = fn()") + + // OAS2RECV + var c = make(chan bool, 10) + c <- false + x, x = <-c + checkOAS2XXX(x, "x, x <-c") + + // OAS2MAPR + var m = map[int]bool{0: false} + x, x = m[0] + checkOAS2XXX(x, "x, x = m[0]") + + // OAS2DOTTYPE + var i interface{} = false + x, x = i.(bool) + checkOAS2XXX(x, "x, x = i.(bool)") +} + +//go:noinline +func fn() (bool, bool) { return false, true } + +// checks the order of OAS2XXX. +func checkOAS2XXX(x bool, s string) { + if !x { + fmt.Printf("%s; got=(false); want=(true)\n", s) + panic("failed") + } +} |