-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
go/types: Generics error message doesn’t match source code when using any
#49583
Comments
It should be noted that this issue does not exist for other constraints, including custom ones |
CC @griesemer This is because any is an alias, and the new compiler type checker has problems keeping track of aliases. The same problem exists for other alias constraints: We have plans for 1.19 to overhaul our handling of aliases. I'm not sure we can do anything for 1.18, unfortunately -- we could try to hack the error message by using a unique pointer for the 'any' empty interface, but that is prone to unintended side effects. I think we need to live with this for 1.18. |
Change https://golang.org/cl/363974 mentions this issue: |
Well, I put my speculative workaround into https://golang.org/cl/363974. It does seem to generally improve type strings, but I'm still wary that we don't fully understand the consequences of such a change. |
Both the 1.17 compiler and the 1.18 compiler have trouble with aliases. This is not new. What is new is that with with 1.18 we introduce The pending CL seems like a fine solution for this for now. |
Change https://golang.org/cl/364194 mentions this issue: |
Make a couple of small changes to support keeping track of the predeclared any by pointer identity, and formatting it as 'any'. This should allow x/tools trybots to pass on CL 363974. Updates golang/go#49583 Change-Id: I79cffee6adbf000a7251dbea4091fdd7b8fdcf0a Reviewed-on: https://go-review.googlesource.com/c/tools/+/364194 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
any
any
What version of Go are you using (
go version
)?Go 1.18 tip
Does this issue reproduce with the latest release?
No, because it includes generics
What operating system and processor architecture are you using (
go env
)?Whatever the go playground runs on
What did you do?
I ran into a compiler error using generics in a switch statement.
https://gotipplay.golang.org/p/XLZZhe3QvIh
What did you expect to see?
T any
was included in the error stringWhat did you see instead?
T interface{}
was used instead. While correct, this doesn’t match the source code and can be confusing.The text was updated successfully, but these errors were encountered: