Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/vet: warn about capturing loop iterator variables #16520
Please answer these questions before submitting your issue. Thanks!
Although this bug pattern most often manifests with
vet already checks for patterns of the form:
The example presented in this Issue is more challenging to analyze because it requires proving that the function is not called within the loop, or at least failing to prove that it is called within the loop. Once the anonymous function has been stored in a data structure or passed to another function, vet can no longer precisely determine when it might be called.
In other words, I think the current vet check is probably as good as we can do without interprocedural analysis.