-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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,go/types: improve error messages when go version is too low #51270
Comments
My 2c: the fundamental problem here is that the compiler and/or type checker can't assume a build system, and so generally avoids being prescriptive in this way. With that said, Ideally we'd expose an error code or wrapped error so that the caller (the Aside: this is actually a good example of where a single error code probably wouldn't suffice. The actual error is "undeclared name"; a possible secondary error is "unsupported feature" (because "any" is unsupported), and it would be nice to surface in a structured way the version at which this feature was introduced. CC @griesemer |
@findleyr no I wasn't using gopls, just running |
Hi @findleyr, it sounds like this was cmd/compile (and not gopls). I sent https://go.dev/cl/390578 yesterday to try to handle some similar cases for cmd/compile, and from a quick look, it seemed like a similar fix would be possible for use of I will probably try a CL for this issue here as well, but wanted to check here first in case that is not sensible for some reason (e.g., based on what you mentioned in #51270 (comment) above). |
Hi @thepudds I think making this change in types2 (a.k.a. cmd/compile) is fine. For philosophical reasons, go/types does not mention go.mod (it is build-system agnostic), but I think we've decided that it's fine for the compiler to do so. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What did you do?
Tried to play with generics after installing go 1.18 RC1, but was a little confused by the error message
when trying to use 1.18 feature like the
any
keyword because I totally forgot about the go version ingo.mod
../main.go:30:25: undeclared name: any (requires version go1.18 or later)
Mentioning
go.mod
in the error message would have helped fixing the error directly instead of having to re-check my config and search for this error message etcWhat did you expect to see?
./main.go:30:25: undeclared name: any (requires version go1.18 or later, current min version in go.mod: go1.16)
What did you see instead?
./main.go:30:25: undeclared name: any (requires version go1.18 or later)
The text was updated successfully, but these errors were encountered: