]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix bad order of evaluation for multi-value f()(g()) calls
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 15 Mar 2022 11:00:16 +0000 (18:00 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 11 May 2022 08:12:15 +0000 (08:12 +0000)
commit7b314d27ce5dbc31eed2076e28c0af4ea8c24473
treedff290a2054f93c353a527edf61919c342f4277d
parente0ae8540ab7527ac8000d6f212526f32b2a9ebad
cmd/compile: fix bad order of evaluation for multi-value f()(g()) calls

The compiler use to compile f()(g()) as:

t1, t2 := g()
f()(t1, t2)

That violates the Go spec, since when "..., all function calls, ... are
evaluated in lexical left-to-right order"

This PR fixes the bug by compiling f()(g()) as:

t0 := f()
t1, t2 := g()
t0(t1, t2)

to make "f()" to be evaluated before "g()".

Fixes #50672

Change-Id: I6a766f3dfc7347d10f8fa3a151f6a5ea79bcf818
Reviewed-on: https://go-review.googlesource.com/c/go/+/392834
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/noder/transform.go
src/cmd/compile/internal/typecheck/const.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/typecheck.go
test/fixedbugs/issue50672.go [new file with mode: 0644]