Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defer_return.md "The defer function must be a function literal declared inside the caller." is not correct #1

Open
tv42 opened this issue Sep 21, 2018 · 0 comments

Comments

@tv42
Copy link

tv42 commented Sep 21, 2018

https://github.com/seebs/notes/blob/master/defer_return.md

It is possible for a deferred function call to modify the return value of its caller in go. For this to happen, two things must be the case: [...] The defer function must be a function literal declared inside the caller.

This is not correct.

func inc(p *int) { *p++ }

func foo() (n int) {
    defer inc(&n)
    return 42
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant