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
cmd/gc: incorrect initialization order #7134
Labels
Milestone
Comments
gccgo is not optimizing away the blank assignment. It's clear that the blank assignment depends on a,b,c,d,e,f, therefore it must be initialized after they are all initialized. However, there are no dependencies among a,b,c,d,e,f, therefore they must be initialized in source code order. So the spec only permits one order for this program, and gccgo implements the spec correctly. |
Here's another (simpler) example of diverging initialization order: http://play.golang.org/p/aYAWMqmJZU The f() calls are simply to illustrate the initialization order - they do not (should not) affect the order in this case. All three front-ends produce different (!) results: 1) gc produces: cbda 2) gccgo produces: abcd 3) go/types produces: bcda d depends on b and c so d comes after b, c. b and c are independent, so they appear in source order, leading to the subsequence bcd for 2) and 3). For 1) the ordering of b and c is as they appear "in the source" of the expression, while for 2) and 3) the ordering is as b and c appear "in the source" of their declarations. Arguably, the interpretation chosen by 2), 3) is more sensible (e.g. independent of different orderings of the same variables in different expressions); and 1) is incorrect. d appears before a in the source, leading to interpretation 3), but a appears before b and c in the source, leading to interpretation 2) (and a is independent of b, c, d). Both 2) and 3) seem valid interpretations of the spec. See also issue #7137 (related, but not the same). Status changed to Accepted. |
Status changed to Duplicate. Merged into issue #7320. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: