Closed
Description
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),