-
Notifications
You must be signed in to change notification settings - Fork 18k
Generics comparable
is allowed non-comparable interfaces
#49584
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
Comments
comparable
is allowed not comparable interfacescomparable
is allowed non-comparable interfaces
From spec:
|
@choleraehyq Yes. That's the point. |
@Code-Hex Compiler doesn't know the underlying type of an interface value at compile time. |
@choleraehyq I understand. However, I don't think it's a good idea to rely on the reflect package to avoid panic. |
The problem is that when we use generics, we are not likely to write code for panic. I believe that We are in a state where I can easily cause a panic. If there is a way to avoid this, I will be happy. |
This is working as expected. This code correctly fails at compile time, because
There is no expectation that I'm going to close this issue as untenable given the current generics design. Feel free to submit a change proposal if you or someone else has a concrete idea about what they would like to change. |
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?
Wrote simple function.
https://gotipplay.golang.org/p/tbKKuehbzUv
What did you expect to see?
Expected to be a compile-time error.
Currently, only the runtime can determine if an argument is not comparable or not. Therefore, to avoid the panic problem, we need to use the reflect package to check whether the two arguments are not comparable or not.
https://gotipplay.golang.org/p/CjLK9zrE1kw
generics code with reflect
If we have to rely on the reflect package, I think this is similar to
https://gotipplay.golang.org/p/Eyp49Gq83n4
code without generics
What did you see instead?
The text was updated successfully, but these errors were encountered: