-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: duplicate case error reports position of constant definition rather than position of previous case #33460
Comments
Nice catch! I'd guess that the intention is to catch different untyped consts with the same value, so I would rather see an addition to the expected error message:
|
Change https://golang.org/cl/188899 mentions this issue: |
Thank you for reporting this bug @jadr2ddude and thank you for chiming in @leitzler! This bug has existed since at least Go1.9. switch {
case 1, 2:
case 2:
} and reported the position but as you've shown, we've got the usual constant variables and the previous logic used their declaration position. I got some time this afternoon, I've mailed https://golang.org/cl/188899 and it'll be fixed for Go1.14. |
Change https://golang.org/cl/188901 mentions this issue: |
Because the Node AST represents references to declared objects (e.g., variables, packages, types, constants) by directly pointing to the referred object, we don't have use-position info for these objects. For switch statements with duplicate cases, we report back where the first duplicate value appeared. However, due to the AST representation, if the value was a declared constant, we mistakenly reported the constant declaration position as the previous case position. This CL reports back against the 'case' keyword's position instead, if there's no more precise information available to us. It also refactors code to emit the same "previous at" error message for duplicate values in map literals. Thanks to Emmanuel Odeke for the test case. Fixes golang#33460. Change-Id: Iec69542ccd4aad594dde8df02d1b880a422c5622 Reviewed-on: https://go-review.googlesource.com/c/go/+/188901 Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Because the Node AST represents references to declared objects (e.g., variables, packages, types, constants) by directly pointing to the referred object, we don't have use-position info for these objects. For switch statements with duplicate cases, we report back where the first duplicate value appeared. However, due to the AST representation, if the value was a declared constant, we mistakenly reported the constant declaration position as the previous case position. This CL reports back against the 'case' keyword's position instead, if there's no more precise information available to us. It also refactors code to emit the same "previous at" error message for duplicate values in map literals. Thanks to Emmanuel Odeke for the test case. Fixes golang#33460. Change-Id: Iec69542ccd4aad594dde8df02d1b880a422c5622 Reviewed-on: https://go-review.googlesource.com/c/go/+/188901 Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It reproduces on the playground.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/Y241bHQreUg
Note: b is used twice in the switch statement
What did you expect to see?
where
./prog.go:18:10
is the position ofb
in the first case statementWhat did you see instead?
where
./prog.go:9:2
is the position of the declaration of the constantb
The text was updated successfully, but these errors were encountered: