Skip to content

Make hashcode of enum items stable #23218

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

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add more enum hashcode tests
  • Loading branch information
mbovel committed May 22, 2025
commit 5c2e39e35d9a884d2669e5e1b22f23b20eee77b0
1 change: 0 additions & 1 deletion tests/run/i19177-stable-enum-item-hashcode.check

This file was deleted.

5 changes: 0 additions & 5 deletions tests/run/i19177-stable-enum-item-hashcode.scala

This file was deleted.

12 changes: 12 additions & 0 deletions tests/run/stable-enum-hashcodes.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
65
65
66
66
67
67
68
68
-1449359058
-1449359058
194551161
194551161
23 changes: 23 additions & 0 deletions tests/run/stable-enum-hashcodes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
enum Enum:
case A
case B
case C()
case D()
case E(x: Int)

@main def Test =
// Enum values (were not stable from run to run before #23218)
println(Enum.A.hashCode)
println(Enum.A.hashCode)
println(Enum.B.hashCode)
println(Enum.B.hashCode)

// Other enum cases (were already stable from run to run)
println(Enum.C().hashCode)
println(Enum.C().hashCode)
println(Enum.D().hashCode)
println(Enum.D().hashCode)
println(Enum.E(1).hashCode)
println(Enum.E(1).hashCode)
println(Enum.E(2).hashCode)
println(Enum.E(2).hashCode)
Loading