Skip to content

cmd/go: set the Go Version for command-line files to be the containing module's Go Version #68159

@samthanawalla

Description

@samthanawalla

Current behavior

The Go version for a file passed in via command-line uses the local version.
e.g. $ go vet -x main.go
will set the Go Version to be the local version.

This happens in 3 places (maybe more):

  1. vet
  2. compiler
  3. init.go

This ignores whether or not the file has a containing module.
e.g. current go version running is 1.23
-> main.go
-> go.mod (1.21)

$ go vet -x main.go
will set the Go Version to be 1.23

New behavior

As discussed offline and in https://go-review.googlesource.com/c/go/+/567435 we have come to the decision to set the Go version to use the containing go.mod's version.
In the above example, $ go vet -x main.go
will set the Go Version to be 1.21

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions