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/vet: warn about break
at end of case/comm clause
#16415
Comments
FWIW, this check is implemented in |
That sounds like |
See https://github.com/dominikh/go-staticcheck/blob/master/testdata/scoped-break.go for the test cases. |
I'm in favor of adding this to vet. |
Seems at least worth gathering data on. I happened to clean up one of these yesterday because it confused me: josharian@0457271. |
CL https://golang.org/cl/26665 mentions this issue. |
I'll repeat my comment I left to @josharian on his josharian@0457271 I wrote:
|
Update #16415 Change-Id: I83e0966931ada2f1ed02304685bb45effdd71268 Reviewed-on: https://go-review.googlesource.com/26665 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
I agree with Brad. More objectively, Brad's point shows that there is a valid and reasonable use for this construct, which makes it unsuitable for vet to prevent. Closing. |
Consider this code from golang.org/cl/24975:
The intention was for the
break
statement to terminate the enclosingfor
loop, but it actually uselessly terminates theswitch
statement instead. Abreak
at the end of aswitch
orselect
statement is always useless, and when the outer context is alsobreak
able, it might be a mistake.I suspect this isn't actually common enough to warrant a cmd/vet check, but thought it at least deserves an issue for discussion.
/cc @alandonovan @robpike
The text was updated successfully, but these errors were encountered: