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: double error when break is not in a loop #51456
Comments
Thanks for reporting this. Tentatively putting it in the 1.19 milestone because it's a (non-serious) 1.18 regression. |
CC @griesemer Rolling forward to 1.20. Please comment if you disagree. Thanks. |
Change https://go.dev/cl/414134 mentions this issue: |
Change https://go.dev/cl/414135 mentions this issue: |
The parser CheckBranches mode checked correct use of break, continue, and labels, but not of fallthrough statements. This CL adds checking of fallthrough statements as well. For #51456. Change-Id: I5000388011973724f80c59a6aaf015e3bb70faea Reviewed-on: https://go-review.googlesource.com/c/go/+/414134 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
The parser CheckBranches mode checked correct use of break, continue, and labels, but not of fallthrough statements. This CL adds checking of fallthrough statements as well. For golang#51456. Change-Id: I5000388011973724f80c59a6aaf015e3bb70faea Reviewed-on: https://go-review.googlesource.com/c/go/+/414134 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
The previous change implemented the missing fallthrough checking in the parser. Therefore we can now disable the duplicate check in the type checker: - rename (types2.Config.)IngoreLabels to IgnoreBranches to more accurately reflect its functionality - now also ignore break/continue/fallthroughs, not just labels The IgnoreBranches flag only exists for types2, for use with the compiler. There's no need to port this code to go/types. Note: An alternative (and perhaps better) approach would be to not use the the parser's CheckBranches mode and instead enable (i.e. not disable) the branch/label checking in the type checker. However, this requires a bit more work because the type checker's error messages about goto's jumping over variables don't have access to the variable names, which are desired in the error messages. Fixes golang#51456. Change-Id: Ib2e71e811d4e84e4895b729646e879fd43b12dcd Reviewed-on: https://go-review.googlesource.com/c/go/+/414135 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
What version of Go are you using (
go version
)?and
Does this issue reproduce with the latest release?
(edit) No, on 1.17.7 it's a single error.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/pyIH7X9EZMT?v=gotip
What did you expect to see?
A single error
What did you see instead?
The text was updated successfully, but these errors were encountered: