You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The error message that go test prints is consistent with that (provided it's not due to #63489):
$ go test
# example.com/m
./p.go:1:34: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
But when doing something like go get go@1.20 (or go mod tidy), the module appears to behave as if it implicitly had the go command's version instead of 1.16.
What did you expect to see?
$ go get go@1.20
go: upgraded go 1.16 => 1.20
go: added toolchain go1.21.3
What did you see instead?
$ go get go@1.20
go: downgraded go 1.21.3 => 1.20
go: added toolchain go1.21.3
The downgraded message is definitely misleading, and we should definitely fix that. 😅
The asymmetric behavior is intentional, though. When we first introduced the go directive we had the property that commands that add it always add the current version, not an old version. But we also have compatibility to contend with, meaning that a go command in a very old repo should use the semantics appropriate to that repo.
Those two goals are in tension, and the way we resolved that tension is: if we are going to write out a go version in a module that did not have one, we write the current version, but if we are not going to write it out we assume an old (and very widely compatible) version.
dmitshur
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Oct 12, 2023
dmitshur
changed the title
cmd/go: module without a go directive doesn't consistently behave as if it had a 1.16 go directive
cmd/go: using go get go@{version} in a module without a go directive can print a misleading "downgraded" message
Oct 12, 2023
What version of Go are you using (
go version
)?What did you do?
https://go.dev/ref/mod#go-mod-file-go specifies:
Consider:
The error message that
go test
prints is consistent with that (provided it's not due to #63489):But when doing something like
go get go@1.20
(orgo mod tidy
), the module appears to behave as if it implicitly had thego
command's version instead of 1.16.What did you expect to see?
What did you see instead?
CC @rsc, @bcmills.
The text was updated successfully, but these errors were encountered: