Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: no "module requires Go 1.nn" warning when a package is not found #51778

Closed
bradfitz opened this issue Mar 18, 2022 · 1 comment
Closed
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Mar 18, 2022

Tested with both Go 1.17.x and Go 1.18(.0)...

If you have a module with a go 1.n directive and try to build with older Go, you get a nice error message ("note: module requires Go 1.18") from cmd/compile when the build fails. This is good:

$ cat go.mod; echo --; cat *.go
module new-symbol

go 1.18
--
package main

import "unicode/utf8"

func main() {
        _ = utf8.AppendRune
}
$ go version
go version go1.18 linux/amd64
$ go run .
$ ~/sdk/go1.17/bin/go run .
# new-symbol
./new-symbol.go:6:6: undefined: utf8.AppendRune
note: module requires Go 1.18

But if the the project is using a new package (say, net/netip in a go 1.18 module) and then a Go 1.17 user tries to build:

$ cat go.mod; echo --; cat *.go
module new-pkg

go 1.18
--
package main

import _ "net/netip"

func main() {
}
pkg$ go version
go version go1.18 linux/amd64
$ go run .
$ ~/sdk/go1.17/bin/go run .
new-pkg.go:3:8: package net/netip is not in GOROOT (/home/bradfitz/sdk/go1.17/src/net/netip)

... they don't get the nice "note: module requires Go 1.18" hint.

Instead they just think you broke the build and file bug reports against you, even though your go.mod says 1.18.

I verified that this bug is still present in 1.18(.0) too:

$ cat go.mod; echo --; cat *.go
module new-pkg

go 1.19
--
package main

import _ "some/future"

func main() {
}
$ go version
go version go1.18 linux/amd64
$ go run .
new-pkg.go:3:8: package some/future is not in GOROOT (/home/bradfitz/sdk/go1.18/src/some/future)

Filed on request of @ianlancetaylor who realized that it was cmd/go that's missing the error.

/cc @bcmills @matloob @nickoneill @josharian

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 18, 2022
@ALTree ALTree added this to the Go1.19 milestone Mar 18, 2022
@ALTree ALTree added the modules label Mar 18, 2022
bradfitz added a commit to tailscale/tailscale that referenced this issue Mar 18, 2022
Due to a bug in Go (golang/go#51778), cmd/go doesn't warn about your
Go version being older than the go.mod's declared Go version in that
case that package loading fails before the build starts, such as when
you use packages that are only in the current version of Go, like our
use of net/netip.

This change works around that Go bug by adding build tags and a
pre-Go1.18-only file that will cause Go 1.17 and earlier to fail like:

    $ ~/sdk/go1.17/bin/go install ./cmd/tailscaled
    # tailscale.com/cmd/tailscaled
    ./required_version.go:11:2: undefined: you_need_Go_1_18_to_compile_Tailscale
    note: module requires Go 1.18

Change-Id: I39f5820de646703e19dde448dd86a7022252f75c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this issue Mar 18, 2022
Due to a bug in Go (golang/go#51778), cmd/go doesn't warn about your
Go version being older than the go.mod's declared Go version in that
case that package loading fails before the build starts, such as when
you use packages that are only in the current version of Go, like our
use of net/netip.

This change works around that Go bug by adding build tags and a
pre-Go1.18-only file that will cause Go 1.17 and earlier to fail like:

    $ ~/sdk/go1.17/bin/go install ./cmd/tailscaled
    # tailscale.com/cmd/tailscaled
    ./required_version.go:11:2: undefined: you_need_Go_1_18_to_compile_Tailscale
    note: module requires Go 1.18

Change-Id: I39f5820de646703e19dde448dd86a7022252f75c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this issue Mar 18, 2022
Due to a bug in Go (golang/go#51778), cmd/go doesn't warn about your
Go version being older than the go.mod's declared Go version in that
case that package loading fails before the build starts, such as when
you use packages that are only in the current version of Go, like our
use of net/netip.

This change works around that Go bug by adding build tags and a
pre-Go1.18-only file that will cause Go 1.17 and earlier to fail like:

    $ ~/sdk/go1.17/bin/go install ./cmd/tailscaled
    # tailscale.com/cmd/tailscaled
    ./required_version.go:11:2: undefined: you_need_Go_1_18_to_compile_Tailscale
    note: module requires Go 1.18

Change-Id: I39f5820de646703e19dde448dd86a7022252f75c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
@bcmills
Copy link
Contributor

bcmills commented Apr 5, 2022

Duplicate of #48966

@bcmills bcmills marked this as a duplicate of #48966 Apr 5, 2022
@bcmills bcmills closed this as completed Apr 5, 2022
@golang golang locked and limited conversation to collaborators Apr 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants