You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mix in the productPrefix hash statically in case class hashCode
Since 2.13, case class `hashCode` mixes in the hash code of the
`productPrefix` string. This is inconsistent with the `equals` method,
subclasses of case classes that override `productPrefix` compare
equal but have a different `hashCode`.
This commit changes `hashCode` to mix in the `productPrefix.hashCode`
statically instead of invoking `productPrefix` at runtime.
For case classes without primitive fields, the synthetic `hashCode`
invokes `ScalaRunTime._hashCode`, which mixes in the result of
`productPrefix`. To fix that, the synthetic hashCode is changed
to invoke `MurmurHash3.productHash` directly and mix in the name
to the seed statically. This works out with keeping `productHash`
forwards and backwards compatible.
The `MurmurHash3.productHash` method is deprecated / renamed to
`caseClassHash`. This method computes the same hash as the synthetic
`hashCode`, except for the corner case where a case class
(or a subclass) override the `productPrefix`. In this case, the
case class name needs to be passed manually to `caseClassHash`.
0 commit comments