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):
- vet
- compiler
- 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