proposal: cmd/go: run vet loopclosure during go test #30176
Labels
FrozenDueToAge
Proposal
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
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: