Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: "goto jumps over declaration" error is unclear for multiple jumped decls #27912
What did you do?
What did you expect to see?
(B1 is the first declaration (on line 9) following the goto.)
What did you see instead?
(B9 is the last declaration (on line 17) following the goto.)
It's confusing what this error means if you're not familiar with the goto variable scope rule, since there are lots of other variable decls in this example that are also skipped that are even closer to the goto statement.
The issue wasn't validity, since the error is technically correct; it's that it left me thinking "why is it okay for b1–b8 but not b9"? The go compiler only reports 8 or so of the topmost (in terms of file position) errors before quitting altogether, so the current approach here of reporting the bottommost error is confusing because it suggests that there were no previous errors.
It's not okay for
I think the compiler "discovers' the error only after finally seeing the label and then it intentionally reports the last and thus nearest jumped-over declaration. Reporting all of the others is definitely possible, the question is if that adds any value for the user. I don't think so.
It would be fine by me to report
It's unnecessary stutter, each less useful for fixing the problem than the last.
It would also be ok to do something like this, if there's more than one decl being jumped over: