-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Dotty allow overriding equals
and hashCode
for Value Classes
#22494
Comments
Other than it being out of spec, what is the issue? Maybe it's better to change the spec since it has been like this from the start. |
Actually, for #22480, since we can define both these methods in source, we can just write them manually to preserve the semantics of those specific classes. So the question is open: Should the implementation change or the spec ? |
I'm using this capability for utilizing the standard collection with my own custom comparison (e.g., grouping lists according to a different criteria than the default equality). I will admit that I'm not sure if indeed the value class saves on boxing/unboxing values for my use-case. |
This issue was picked for the Scala Issue Spree of tomorrow, Monday, February 3rd. @hamzaremmal, @julian-a-avar-c and @nmcb will be working on it. |
I have a vague recollection that this change was intentional. It's always been frustrating that we couldn't override At this point I think we should change the spec instead. |
@soronpo can you link to your use-case ? |
@hamzaremmal: if this is in the end should be a specification change, should we try to find an alternative issue for today's Spree? |
@mbovel Yes please |
Here would be my use case ("would" because this code still cross-compiles for Scala 2.12, so ...):
def equals(x: UTF8String, y: UTF8String): Boolean =
java.util.Arrays.equals(x.bytes, y.bytes)
def hashCode(x: UTF8String): Int =
scala.util.hashing.MurmurHash3.bytesHash(x.bytes) |
In today's Core Meeting, we have decided to modify the specification of Value Classes to allow the definition of |
Compiler version
590691b
Minimized code
Output
Compiles.
Expectation
Dotty should prohibit overriding
equals
andhashCode
per the Value Classes's specification; SIP-15:The text was updated successfully, but these errors were encountered: