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
NeedsFix
Milestone

Comments

@alecthomas
Copy link

@alecthomas alecthomas commented Nov 4, 2021

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 label Nov 4, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Nov 4, 2021
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 4, 2021

CC @griesemer @findleyr

@findleyr
Copy link
Contributor

@findleyr 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 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

@griesemer griesemer commented Nov 5, 2021

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

@gopherbot gopherbot commented Nov 5, 2021

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

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 8, 2021

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix
Projects
None yet
Development

No branches or pull requests

5 participants