Skip to content
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: add Config.GoVersion field #61176

Closed
rsc opened this issue Jul 5, 2023 · 4 comments
Closed

x/tools/go/analysis: add Config.GoVersion field #61176

rsc opened this issue Jul 5, 2023 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Proposal Proposal-Accepted release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jul 5, 2023

To fix #61174 and set up for future changes in Go 1.22, the go command needs to pass the Go version in the compiler config. This requires adding a new GoVersion string field to the Config struct and then passing it through to the types.Config for the package. The full diff is:

diff --git a/go/analysis/unitchecker/unitchecker.go b/go/analysis/unitchecker/unitchecker.go
index ff22d23ce..10c76bc62 100644
--- a/go/analysis/unitchecker/unitchecker.go
+++ b/go/analysis/unitchecker/unitchecker.go
@@ -62,6 +62,7 @@ type Config struct {
 	Compiler                  string
 	Dir                       string
 	ImportPath                string
+	GoVersion                 string // minimum required Go version, such as "go1.21.0"
 	GoFiles                   []string
 	NonGoFiles                []string
 	IgnoredFiles              []string
@@ -217,8 +218,9 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
 		return compilerImporter.Import(path)
 	})
 	tc := &types.Config{
-		Importer: importer,
-		Sizes:    types.SizesFor("gc", build.Default.GOARCH), // assume gccgo ≡ gc?
+		Importer:  importer,
+		Sizes:     types.SizesFor("gc", build.Default.GOARCH), // assume gccgo ≡ gc?
+		GoVersion: cfg.GoVersion,
 	}
 	info := &types.Info{
 		Types:      make(map[ast.Expr]types.TypeAndValue),
@rsc rsc added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Jul 5, 2023
@rsc rsc added this to the Proposal milestone Jul 5, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/507976 mentions this issue: cmd/go: pass GoVersion in vet config

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/507880 mentions this issue: go/analysis: pass package's Go version to type checker

@rsc
Copy link
Contributor Author

rsc commented Jul 5, 2023

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

gopherbot pushed a commit that referenced this issue Jul 6, 2023
When invoking a vet tool with -vettool (or vet itself),
we need to pass the package's GoVersion to use when
analyzing the package.

The test of this behavior is in the x/tools/go/analysis CL 507880.

For #61176.

Change-Id: I3b5a90fcd19a0adc7fb29366e106e18f722fc061
Reviewed-on: https://go-review.googlesource.com/c/go/+/507976
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
@rsc
Copy link
Contributor Author

rsc commented Jul 12, 2023

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

@rsc rsc changed the title proposal: x/tools/go/analysis: add Config.GoVersion field x/tools/go/analysis: add Config.GoVersion field Jul 12, 2023
@rsc rsc modified the milestones: Proposal, Backlog Jul 12, 2023
bradfitz pushed a commit to tailscale/go that referenced this issue Jul 15, 2023
When invoking a vet tool with -vettool (or vet itself),
we need to pass the package's GoVersion to use when
analyzing the package.

The test of this behavior is in the x/tools/go/analysis CL 507880.

For golang#61176.

Change-Id: I3b5a90fcd19a0adc7fb29366e106e18f722fc061
Reviewed-on: https://go-review.googlesource.com/c/go/+/507976
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
@dmitshur dmitshur modified the milestones: Backlog, Unreleased Jul 21, 2023
@golang golang locked and limited conversation to collaborators Jul 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Proposal Proposal-Accepted release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants