-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
cmd/vet: do not report variable capture for loop variables with the new lifetime rules #63888
Comments
Example of a false positive https://go.dev/play/p/WsTuyNr6YnK
Playground output for Go 1.21:
Playground output for Go dev branch:
The dev currently branch implements the https://go.dev/issue/60078 loop lifetimes. So go vet should not continue to report on this example after 1.22. |
Note this will need to support packages with a mixture of lifetimes in different files or files without |
Change https://go.dev/cl/539016 mentions this issue: |
Uses the (*types.Info).FileVersion to disable the loopclosure checker when in an *ast.File that uses GoVersion >= 1.22. Updates golang/go#62605 Updates golang/go#63888 Change-Id: I2ebe974bc2ee2323eafb0f02d455ab76b3b9268d Reviewed-on: https://go-review.googlesource.com/c/tools/+/539016 Run-TryBot: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Fixed by https://go.dev/cl/c/go/+/543975 |
I still see this issue with 1.22.0:
|
@alexaandru Thank you for the report. I opened #65612. Looks like a plumbing issue when running vet on files listed on the command line. You can either invoke vet differently, suppress the finding (add |
This issue tracks support in x/tools/go/analysis/passes/loopclosure for the new loop variable lifetime rules of https://go.dev/issue/60078, available now behind GOEXPERIMENT=loopvar and likely on for language versions >= 1.22.
Marking as a release blocker as this will make cmd/vet would report a large number of false positives due to the new language feature.
The text was updated successfully, but these errors were encountered: