Skip to content

go/types: add Package.GoVersion method #61175

@rsc

Description

@rsc

For #61174, it would be good for individual checkers to be able to find out the Go version associated with a given package. The code will start tracking this, but we should export it as well. Strictly speaking this is not necessary for Go 1.21, but I suggest we include it now, since it will be necessary for Go 1.22 and it will be easier for tool authors if all the related changes are in the same Go version.

The new method is:

// GoVersion returns the minimum Go version required by this package.
// If the minimum version is unknown, GoVersion returns the empty string.
// Individual source files may specify a different minimum Go version,
// as reported in the [go/ast.File.GoVersion] field.
func (pkg *Package) GoVersion() string { return pkg.goVersion }

The goVersion is set during type-checking, copied from Config.GoVersion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions