Closed
Description
Within standard library packages the GoVersion sent to unitchecker is "" for standard library packages. This can be recreated from gotip vet -x ./...
from $GOROOT/src
(which will be in a module).
This GoVersion
is passed along to go/types
in types.Config
. When this is empty (which is an invalid version), (*types.Info).FileVersions
is not populated. The loopclosure
vet check uses FileVersions
to decide what is the semantics of a given for loop is. So there will now be a divergence in behavior for cmd/vet when running on the standard libraries.
The relevant code to set the field is in buildVetConfig
:
if a.Package.Module != nil {
v := a.Package.Module.GoVersion
if v == "" {
v = gover.DefaultGoModVersion
}
vcfg.GoVersion = "go" + v
}
A hunch for why a.Package.Module
is nil is that it comes from PackageModuleInfo
which documents that nil is expected:
// PackageModuleInfo returns information about the module that provides
// a given package. If modules are not enabled or if the package is in the
// standard library or if the package was not successfully loaded with
// LoadPackages or ImportFromFiles, nil is returned.
func PackageModuleInfo(ctx context.Context, pkgpath string) *modinfo.ModulePublic {
cc @bcmills