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/compile: improve messaging for Go version requirements #49368

Closed
alecthomas opened this issue Nov 4, 2021 · 6 comments
Closed

cmd/compile: improve messaging for Go version requirements #49368

alecthomas opened this issue Nov 4, 2021 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@alecthomas
Copy link

From helping out in the #generics channel on Gophers Slack, I've noticed that numerous people run into the following (or similar) error message when writing generics code against gotip:

embedding interface element ~int|~int8|~int16|~int32|~int64 requires go1.18 or later

As they are using go-1.18, and the error message doesn't say anything about the "go" stanza in the go.mod file, they are left confused as to how to solve this.

I suggest that this error message be improved to include more detail, similar to:

embedding interface element ~int|~int8|~int16|~int32|~int64 requires go1.18 or later but go.mod specifies go 1.17

or

embedding interface element ~int|~int8|~int16|~int32|~int64 requires go1.18 or later but go 1.17 is being used
@ianlancetaylor ianlancetaylor changed the title Improve messaging for Go version requirements cmd/compile: improve messaging for Go version requirements Nov 4, 2021
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 4, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Nov 4, 2021
@ianlancetaylor
Copy link
Contributor

CC @griesemer @findleyr

@findleyr
Copy link
Contributor

findleyr commented Nov 5, 2021

We don't want a type checker error message mentioning go.mod as we can't assume modules, but perhaps we could say something like

embedding interface element ~int|~int8|~int16|~int32|~int64 requires go1.18 or later (-lang=go1.17)

I think we're unlikely to patch Go 1.17 or earlier for this.

@findleyr
Copy link
Contributor

findleyr commented Nov 5, 2021

Another thought: something we've had on the back-burner for a while is exposing more structured data from type checker errors: an error code or wrapped error that can be interpreted by tools like the go command or gopls.

This is an example of where such additional signal could be useful, as the Go command or gopls could detect that an error was due to language version and suggest changing the go.mod go version. Unfortunately that's not going to happen for 1.18, but perhaps we can still make the error message clearer.

@griesemer
Copy link
Contributor

The type checker used by the compiler does know that it's used by the compiler (it's configured to issue compiler-specific error messages), so it could actually just use the old message of the compiler here that refers to the -lang flag. I will take care of this.

@griesemer griesemer self-assigned this Nov 5, 2021
@gopherbot
Copy link

Change https://golang.org/cl/361411 mentions this issue: cmd/compile/internal/types2: use compiler version error when configured for compiler

@gopherbot
Copy link

Change https://golang.org/cl/361963 mentions this issue: cmd/go: fix long test builders

gopherbot pushed a commit that referenced this issue Nov 8, 2021
CL 361411 improved error message for go version requirement, but forgot
to update the test in cmd/go to match new error message. That causes
longtest builders failed.

This CL changes mod_vendor_goversion.txt to match compiler error, and
limit fixedbugs/issue49368.go to run with -G=3 only.

Updates #49368

Change-Id: I125fe0a8c2a1595066d39c03e97819e7a1274e0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/361963
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants