Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/vet: rangeloop: inspect all go/defer statements prior to a loop back edge #30649
Running go vet on this file:
If I change loop body to this:
then go vet prints nothing.
Looking at the vet source code, checkRangeLoop can just judge a go or defer statement for body to see whether a variable is capture, which means vet will be failed if it exists condition sentence before a go or defer statement
This is an interesting special case that we could easily extend the check to handle without the full generality of #16520, which is much harder to solve. Specifically: the go/defer statement is still the last statement within the loop body, if we use a slightly more generalized definition of "last" that traverses down into control constructs (such as