-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/tools/go/analysis/passes/stdversion: spurious reports in files tagged //go:build 1.<old> #67123
Comments
Change https://go.dev/cl/582595 mentions this issue: |
As long as the module version is go1.21 or later, this is working as intended. Starting with 1.21, If the module version was 1.20 or earlier, this should not be an error (we should write a test). |
Got it; sorry for the confusion. There is still something strange about the meaning of tags. A build constraint of |
I don't believe so. go/parser/parser.go does the following:
go/build/constraint's doc:
(The level of complexity here is kinda frustrating.) |
You're absolutely right: https://go.dev/play/p/Ifets4t1wMk. (I never studied the constraint evaluation logic closely before.) It seems like the only thing needed here is a test of the 1.20 case. Thanks, all. |
Considering the original issue: if stdversion is working as intended, does that mean cmd/compile has a bug? Should it reject an attempt to call strings.Cut (go1.18) when compiling the file with go1.16 semantics? |
Change https://go.dev/cl/582958 mentions this issue: |
Change https://go.dev/cl/582936 mentions this issue: |
Change https://go.dev/cl/582959 mentions this issue: |
See golang/go#67123 Change-Id: I05d602c1b5decb709473d6f0648837ae4270e9fe Reviewed-on: https://go-review.googlesource.com/c/build/+/582958 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Alan Donovan <adonovan@google.com>
We've only ever used build constraints to increase the minimum required Go version. For example, CL 336390 in 2021 bumped them to go1.16 to use //go:embed sooner. By now, the 'go' directive in go.mod lets us do that for the entire module, and Go 1.21 is the minimum supported version, so there's no need for those old constraints. Also expand build constraints within a few packages, so that they're in all its source files rather than an arbitrary subset. Finally, clean up a few older '// +build'-style constraint instances. For golang/go#67123. Change-Id: Ia1d1c3112eab3b72bf808887f27b5fcb2fd894e2 Reviewed-on: https://go-review.googlesource.com/c/build/+/582959 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
The stdversion analyzer, which will soon become part of the vet suite (see https://go.dev/cl/582556), gives false positives when run on files that, although part of modules with recent Go versions, have old build tags. In this example from x/build, the file is tagged 1.16 even though the module requires go1.21.
stdversion should only honor the file version if it is greater than the module version. (And perhaps some other tool should warn when a file's build tag is so old that it becomes redundant with the module version.)
The text was updated successfully, but these errors were encountered: