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/compile: allows assigning to blank identifier in struct #31546
Comments
it seems to be a regression of https://go-review.googlesource.com/c/go/+/38006/ |
@cuonglm the discussion in #19482 (which that CL fixes) indicates that the previous behavior is wrong. But maybe I'm misinterpreting what the "it" is that was the regression. There are some possibly related cases in #15481.
This seems to be the crux of the issue. I think we need to start with some clarity about what the correct behavior is here. (Or whether it is ok for the value of the blank field to be implementation dependent.) |
If you told me one was legal and asked me what I expect to happen without looking at the spec or testing it in the playground, I would say
which is effectively equivalent to
But I also think that https://play.golang.org/p/Qzcyybi8ZUV should print 0 by the same logic, so maybe I'm not the best person to ask 😄 |
The reason there's any assignment allowed at all is for: type T struct {x, _, z int} where the _ is padding. The literal assignment fell out from changing the rules to allow the whole-struct assignment but was probably a mistake. If we had it to do over again, we could probably disallow:
But we don't have it to do over again, and it is silly to insist on writing the _ field, so it seems like we must insist on not writing it during the literal. So the global is the wrong behavior that needs fixing. |
Working on a fix. |
Change https://golang.org/cl/173723 mentions this issue: |
https://play.golang.org/p/WMC4t5oiRR-
Currently (Go 1.12, master) says:
The
x == y
part returningtrue
is defined by the spec, butx
andy
getting a different value for the blank identifier is... weird. I see nothing in the spec that addresses this directly but if squint I might be able to connect some different parts and make guesses as to intent.But Go 1.4 - Go 1.8 fail to compile with:
Go 1.9 is the first version where the program above compiles and returns that result.
/cc @ianlancetaylor @griesemer @josharian @cherrymui @randall77 @davecheney
The text was updated successfully, but these errors were encountered: