Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Compare productPrefix in synthetic case class canEqual#10859

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
lrytz wants to merge1 commit intoscala:2.13.xfromlrytz:t13033

Conversation

@lrytz
Copy link
Member

@lrytzlrytz commentedSep 10, 2024
edited
Loading

Since 2.13, case classhashCode mixes in the hash code of the
productPrefix string. The syntheticequals method has fallen
out of sync in that regard, so two instances can be equal but have
different hash codes.

This commit changes the syntheticcanEqual method to also compare
theproductPrefix of the two instances.

Fixesscala/bug#13033

@scala-jenkinsscala-jenkins added this to the2.13.16 milestoneSep 10, 2024
@lrytz
Copy link
MemberAuthor

(should forward-port/report to Scala 3 once approved)

@lrytzlrytzforce-pushed thet13033 branch 2 times, most recently fromcd7b384 to7315f51CompareSeptember 11, 2024 11:54
@retronym
Copy link
Member

👍🏽 for thecanEqual approach.

Since 2.13, case class `hashCode` mixes in the hash code of the`productPrefix` string. The synthetic `equals` method has fallenout of sync in that regard, so two instances can be equal but havedifferent hash codes.This commit changes the synthetic `canEqual` method to also comparethe `productPrefix` of the two instances.
@lrytzlrytz changed the titleAdddeprecatedOverriding to synthetic case classproductPrefixCompare productPrefix in synthetic case class canEqualSep 12, 2024
@SethTisue
Copy link
Member

@lrytz do we need to release-note this, might it cause mysterious breakage?

@lrytz
Copy link
MemberAuthor

Yes, it changes case class equality.

scala> case class C(x: Int)class Cscala> class D extends C(1) { override def productPrefix = "D" }class Dscala> C(1) == new Dval res0: Boolean = false

That istrue in 2.13.15.

@SethTisueSethTisue added the release-notesworth highlighting in next release notes labelSep 17, 2024
@SethTisue
Copy link
Member

we'll need a comparable PR on the Scala 3 side, yes?

@lrytz
Copy link
MemberAuthor

Yes. I can submit it there to probe what the 3 folks think about the semantic change.

SethTisue reacted with thumbs up emoji

@SethTisue
Copy link
Member

@lrytz where does this stand, after the discussion onscala/scala3#21606 ?

@lrytzlrytz modified the milestones:2.13.16,2.13.17Nov 13, 2024
@lrytz
Copy link
MemberAuthor

@sjrd points out that this fix goes the wrong way around; what we want is to define semantics ofequals and then adjust thehashCode to be compatible. This PR does the opposite.

So here's my attempt to fixhashCode instead:#11023

@lrytzlrytz closed thisMar 20, 2025
@SethTisueSethTisue removed this from the2.13.17 milestoneMar 20, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@retronymretronymAwaiting requested review from retronym

Assignees

No one assigned

Labels

release-notesworth highlighting in next release notes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

OverridingproductPrefix breaks case class hash code

4 participants

@lrytz@retronym@SethTisue@scala-jenkins

[8]ページ先頭

©2009-2025 Movatter.jp