loader: enforce Go language version in the type checker

This means for example that ranging over integers will only work when
setting the Go version to go1.22 or later in the go.mod file.
This commit is contained in:
Ayke van Laethem
2024-01-18 20:05:14 +01:00
parent 53db436a7d
commit 08ca1d13d0
+6
View File
@@ -378,6 +378,12 @@ func (p *Package) Check() error {
typeErrors = append(typeErrors, err)
}
checker.Importer = p
if p.Module.GoVersion != "" {
// Setting the Go version for a module makes sure the type checker
// errors out on language features not supported in that particular
// version.
checker.GoVersion = "go" + p.Module.GoVersion
}
// Do typechecking of the package.
packageName := p.ImportPath