-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
spec: clarify order in which operands of multi-value assignments are evaluated #27821
Comments
For what it's worth, tip gccgo behaves like gc. See #23188. |
I think the proposal is simple, but I think it's backwards incompatible in a subtle way that I don't think we want to commit to. In particular, today we guarantee If we define that I'll also emphasize this does not reflect how cmd/compile implements parallel assignments. |
@go101 No, I commented on this issue as intended. Today, this code:
means:
It does not mean:
In particular, today a Go compiler is not allowed to panic because |
The current issue only tries to clarify the rule before the second phase (carry-out phase) in executing a multi-value assignments. More specifically, it tries to clarify that the addresses of the target values must be confirmed before executing the second phase. It is totally single-value assignments unrelated. For your example, this issue doesn't try to clarify the evaluation order of [Update]: What this issue tries to clarify is the expressions |
@mdempsky The proposed description in the first comment is probably too long. The following shorter one might be better:
|
But that's not the case today, so it's not a clarification. For example:
This program prints |
It executes as expected:
This issue tries to clarify that the execution of |
Why Alternatively, consider this:
Based on your original comment, it sounds like you think the
But it doesn't. |
Eh, yes, the original description is not perfect. |
Do I understand correctly that your proposal is now just:
? If so, I find this more confusing than the spec wording it's meant to clarify. E.g., it uses phrases that don't appear anywhere in the Go spec like "carry-out phase" and "confirmed". I also don't think there's any dispute over the idea that assignments that happen during phase 2 don't affect (sub)expressions that were evaluated during phase 1. |
There is a line There ever were the disputes, at least at the time when the issue was created. |
I modified it as
|
(This issue is separated from #27804 after I realized it is not a proposal but just a doc improvement. There are no language changes in the improvement.)
Currently, for assignments in Go, Go specification specifies
The rule description is some ambiguous. It doesn't specify clearly how the operands in the mentioned expressions on the left should be exactly evaluated. This is the cause of some disputes.
For the following program, if it is compiled with
gccgo
(version 8), then it will panic. But if it is compiled with the standard Go compiler, then the program will exit without panicking.Obviously, gccgo think the multi-value assignment is equivalent to
However, the standard Go thinks it is equivalent to
Most Go team members think the interpretation of the standard Go compiler is what Go specification wants to express. I also hold this opinion.
To avoid description ambiguities, it would be good to append the following description to the rule.
I think these supplement descriptions can avoid the above mentioned disputes.
[update at Oct. 18, 2019]: an imperfection is found by @mdempsky. The below is a simpler alternative improved description:
The text was updated successfully, but these errors were encountered: