-
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
proposal: cmd/go: run vet loopclosure during go test #30176
Comments
Earlier open issue and discussion about adding a vet check #16520 |
Can someone characterize the false positives for loopclosure? The docs in loopclosure.go say:
In this case it seems like the reason it's not on by default is it doesn't catch very much. It does catch this one example. Maybe that's enough? Damien, you said that we've been running it inside Google and also claimed that it catches a common mistake, but it looks like it will flag very few of the actual mistakes I've seen, because of the restriction about looking only at the final statement of the loop. Do you know if this has caught real mistakes inside Google, and if so how many? |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Go test runs a high-confidence set of go vet checks when building a test binary. I propose adding the "loopclosure" check to that set.
The loopclosure check looks for references to loop variables from within nested functions. For example, it will catch the bug in the following code, which will usually (depending on the whim of the scheduler) print
222
rather than012
.:We've been running this analyzer as part of all Go builds inside Google for a while now (not just tests). It catches a common coding mistake (FAQ entry https://golang.org/doc/faq#closures_and_goroutines). While it's theoretically possible that valid code could depend on the behavior it tests for, I've never seen any such code in practice. We should turn it on by default.
The text was updated successfully, but these errors were encountered: