scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Make hashcode of enum items stable

Open mbovel opened this issue 6 months ago • 2 comments

Fixes #19177. Done during the compiler issue spree of Monday, May 19th.

Note: hashCode of String is cached (see https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/String.java#L2403-L2436), so this change should not introduce a significant performance overhead.

mbovel avatar May 21 '25 12:05 mbovel

I think a proper check should show different cases have different hashes and also if you have a case with an argument that two instances with the same argument have the same hash.

soronpo avatar May 22 '25 15:05 soronpo

@soronpo I added both tests. This PR only changes the hashcode of "enum values" (cases without parentheses), but it's probably still good to test the other cases as well.

mbovel avatar May 22 '25 15:05 mbovel