Skip to content

x/website/_content/blog: defer statements execute before/after the caller returns #45889

Open
@howardtw

Description

@howardtw

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

$ go version
go version go1.16.2 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

What did you do?

In this example the defer function doesn't change the returned value whereas using the named return values would do the trick in this example.

If the defer function is executed after the caller returns as this blog post suggests, that would explain it. However, the doc says defer functions are executed before the caller returns.

What did you expect to see?

The blog post and the Golang doc being consistent.

What did you see instead?

The blog post says the list of saved calls is executed after the surrounding function returns whereas the Golang doc says the list of saved calls is executed before the surrounding function returns

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.help wantedwebsite

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions