-
Notifications
You must be signed in to change notification settings - Fork 18k
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: const decl with missing RHS interpreted subtly differently with 1.18 #49157
Comments
CC @griesemer |
Nice pathological case! |
I am missing what the pathology is, and why s/textual/lexical/ makes a difference. Please fill me in. |
In the first example, simply repeating the last present RHS where it is omitted leads to a different result (than leaving the RHS away) because the Agreed that I don't know how using "lexical" would make this clearer. But stating that |
I just wrote, "I still don't see the problem. You're created a new variable called iota, so of course it's different." and in writing that saw the problem. Wow, nice corner case. |
In fact, this is not an package main
const X = 3
func main() {
const (
X = X + X
Y
)
println(X, Y)
} |
Looking at this again, it turns out that in Go 1.18 (with the new type checker) we actually get exactly the result as prescribed by the spec. For this example: package main
const X = 3
func main() {
const (
X = X + X
Y
)
println(X, Y)
} Running with Go 1.18 we get the result 6 and 12, which corresponds exactly to using textually Running with 1.17 we get the result 6 and 6, corresponding to a copy of the syntax tree for We have two possibilities:
There is a backward-compatibility issue here but this is a pathological situation that is unlikely to occur in correct code in the wild, and since 1.18 is out we have not heard any complaints about this. Thus I am inclined to go 2) and close this issue. @ianlancetaylor @robpike @rsc for feedback. |
Marking as release blocker in case we decide that this needs to be handled as a regression. |
2 |
Current gccgo prints I'm fine with changing that. |
Closing as working as intended since Go 1.18, per feedback. |
We should add a test case or two for this if we don't already have one. |
@ianlancetaylor Yes, I was planning to do that. |
Change https://go.dev/cl/414795 mentions this issue: |
Add analogous tests to go/types and types2 test suites. Make sure "assert" built-in is available in type-checker tests. For #49157. For #53585. Change-Id: I092901ecb43eb4833c09bd8f5e38efbe0285babe Reviewed-on: https://go-review.googlesource.com/c/go/+/414795 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Add analogous tests to go/types and types2 test suites. Make sure "assert" built-in is available in type-checker tests. For golang#49157. For golang#53585. Change-Id: I092901ecb43eb4833c09bd8f5e38efbe0285babe Reviewed-on: https://go-review.googlesource.com/c/go/+/414795 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
The current spec says:
By the explanation, the following two declarations are equivalent but are not actually (assume they are in local blocks):
It would be better to change "textual" into "lexical".
The text was updated successfully, but these errors were encountered: