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

multiple-value-return plays badly with access to return variables in defer #846

Closed
rogpeppe opened this issue Jun 8, 2010 · 4 comments
Closed

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented Jun 8, 2010

the following code causes the compiler to give the
message: "error in shape across RETURN"

package test

func x() (a int, b string) {
    defer func(){
        a++
    }()
    return y()
}

func y() (int, string) {
    return 0, ""
}

8g darwin 386 443fb42ed60e+ tip
@peterGo
Copy link
Contributor

peterGo commented Jun 8, 2010

Comment 1:

When I changed a++ to refer to a local variable x instead of a parameter, there was no
compiler error.
package test
func x() (a int, b string) {
    var x int
    defer func() {
        x++
    }()
    return y()
}
func y() (int, string) {
    return 0, ""
}

@rogpeppe
Copy link
Contributor Author

rogpeppe commented Jun 8, 2010

Comment 2:

that's right. any reference to a return parameter in the defer triggers the
error. (in the original code, the bug was triggered by a call to Print)

@griesemer
Copy link
Contributor

Comment 3:

Labels changed: added compilerbug.

Owner changed to r...@golang.org.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jul 15, 2010

Comment 4:

This issue was closed by revision ece6a8c.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants