-
Notifications
You must be signed in to change notification settings - Fork 569
Incorrect lhs evaluation order in multi-assignments #358
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
Comments
I found this kind of fascinating so I looked into it. So this breaks in GopherJS (the assignment itself doesn't break; a later
This breaks in Go and GopherJS, in the same way as the above, and is probably what GopherJS is doing:
This works in Go and GopherJS, and is probably what GopherJS should be doing:
The Go spec says
So GopherJS is apparently violating the "First" bit, in this case. |
I can reproduce. This looks like a valid bug. Thanks for the report @shibukawa and for looking into it @theclapp. I think your analysis is correct. |
@shibukawa Thanks for the bug report. Please give me some time to fix it, since the solution is not straightforward. JS has no pointers, they can only be emulated which is slow. I want to avoid this and instead have a more involved solution which is fast for the most cases. |
Thank you! It is not urgent for me because my code already uses working around code to avoid this issue. Enjoy holidays. Gopher.js is awesome. |
@renfredxh just ran into this too. We worked around it, so it's not urgent, but fixing this will definitely be nice. |
Copying from #1063: The spec says the following:
However, gopherjs evaluates lhs expressions at the time of assignment. In situations when one of the assignments modifies a variable referenced by another assignment, the result may be incorrect. For example: package main
func main() {
type T struct{ i int }
var x T
p := &x
p, p.i = new(T), 4
println(p.i, x.i)
} Go prints Related: golang/go#23017. |
The following code reproduces the issue I met.
https://gist.github.com/shibukawa/44cb0529c492e0679e9c
I am using one slice technique, deleting pointer member, described at here:
https://github.com/golang/go/wiki/SliceTricks
The result is different from Golang. Gopher.js overwrites the last member that should not be removed with nil.
The text was updated successfully, but these errors were encountered: