-
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, types2: confusing error message when using comparable in a union #49602
Comments
I got the same error in a similar case. comparable interface should be treated as a union of enumerated comparable types, so expect to be able to use it in a union. (I think comparable interface does not contain method as a constraint.)
|
CC @griesemer This is working as intended, at least for Go 1.18. See #45346 (comment) for more context. With respect to computing type sets, comparable behaves like an interface with methods. I agree that we should improve the error message, however. |
comparable
union raises compile error
Thank you for your comment. To be honest, I didn't understand why comparable types are not allowed to be used in unions. (As spec) This is just curious. Are there any resources or links that can help me? |
Eventually there will be better documentation. We're in the middle of writing it. Suffice to say that for 1.18 at least, Will keep this open to improve the error message. |
Change https://golang.org/cl/372674 mentions this issue: |
Change https://golang.org/cl/372694 mentions this issue: |
Change https://golang.org/cl/372954 mentions this issue: |
For #49602. Change-Id: I0d3ff8f087dffb3409918494147fd1dceff7514d Reviewed-on: https://go-review.googlesource.com/c/go/+/372694 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
This is a port of CL 372674 from types2 to go/types with minor adjustments for error handling. For #49602. Change-Id: I726081325a2ff2d5690d11ddc8a830bbcbd8ab33 Reviewed-on: https://go-review.googlesource.com/c/go/+/372954 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Robert Findley <[email protected]>
What version of Go are you using (
go version
)?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?
https://gotipplay.golang.org/p/FSMOjCXAtSL
What did you expect to see?
can compile
What did you see instead?
compile error
./prog.go:6:66: cannot use comparable in union (interface contains methods)
The text was updated successfully, but these errors were encountered: