Skip to content

cmd/compile: return statement does not set result parameters before executing deferred function returned by a literal function #32175

@sandan

Description

@sandan

What version of Go are you using (go version)?

$ go version
go version go1.12.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mark/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

See the playground example: https://play.golang.org/p/SptuCsFa3uw
I have two defer statements in their own functions. They both call anonymous functions that return a function to execute at the end of the function (when the result variable has been assigned the value in the return statement).

The functions differ in how the result variable is assigned it's value. One does it implicitly by returning the expression. The other does a bare return after modifying the named return variable.

What did you expect to see?

I expected to see the anonymous function (that prints "on exit") print the result variable with a value of 16 in the not_working() function.

What did you see instead?

That anonymous function printed 0 for the result return variable (the initial value of the result name return variable).

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions