Avoid NPE when calling hashCode on a value class wrapping null#11204
Merged
lrytz merged 1 commit intoscala:2.13.xfrom Jan 27, 2026
Merged
Avoid NPE when calling hashCode on a value class wrapping null#11204lrytz merged 1 commit intoscala:2.13.xfrom
lrytz merged 1 commit intoscala:2.13.xfrom
Conversation
sjrd
reviewed
Jan 22, 2026
src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
Outdated
Show resolved
Hide resolved
Member
|
Noting that
|
Member
Author
This PR also fixes Why would it be less safe to change? I'll add a test. |
6002346 to
d2b5b1b
Compare
sjrd
approved these changes
Jan 23, 2026
Contributor
|
Not sure if it needs to be added that "not fixed in dotty". Details``` at pprint.Walker.treeify$$anonfun$1$$anonfun$7(Walker.scala:118) at pprint.Renderer.str$lzyINIT1$1(Renderer.scala:145) at pprint.Renderer.str$1(Renderer.scala:146) at pprint.Renderer.rec(Renderer.scala:147) at pprint.PPrinter.tokenize(PPrinter.scala:165) at pprint.PPrinter.apply(PPrinter.scala:119) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:565) at dotty.tools.repl.Rendering.pprintRender(Rendering.scala:62) at dotty.tools.repl.Rendering.replStringOf(Rendering.scala:108) at dotty.tools.repl.Rendering.valueOf$$anonfun$2(Rendering.scala:124) at scala.Option.map(Option.scala:244) at dotty.tools.repl.Rendering.valueOf(Rendering.scala:124) at dotty.tools.repl.Rendering.renderVal(Rendering.scala:166) at dotty.tools.repl.ReplDriver.$anonfun$9(ReplDriver.scala:460) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:327) at dotty.tools.repl.ReplDriver.extractAndFormatMembers$1(ReplDriver.scala:460) at dotty.tools.repl.ReplDriver.renderDefinitions$$anonfun$2(ReplDriver.scala:498) at scala.Option.map(Option.scala:244) at dotty.tools.repl.ReplDriver.renderDefinitions(ReplDriver.scala:497) at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:402) at scala.util.Either.fold(Either.scala:199) at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:384) at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:343) at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:256) at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:264) at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:298) at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:272) at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:79) at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:272) at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:264) at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:166) at dotty.tools.repl.Main$.main(Main.scala:8) at dotty.tools.repl.Main.main(Main.scala) ``` |
Member
Author
Yeah, I'll port it to 3. |
lrytz
added a commit
to lrytz/scala3
that referenced
this pull request
Jan 26, 2026
Change the synthetic hashCode for value classes from def hashCode(): Int = this.underlying.hashCode to def hashCode(): Int = java.util.Objects.hashCode(this.underlying) (unless the underlying value is primitive) Forward-port of scala/scala#11204
lrytz
added a commit
to scala/scala3
that referenced
this pull request
Jan 27, 2026
Change the synthetic hashCode for value classes from
def hashCode(): Int = this.underlying.hashCode
to
def hashCode(): Int = java.util.Objects.hashCode(this.underlying)
(unless the underlying value is primitive)
Forward-port of scala/scala#11204
WojciechMazur
pushed a commit
to scala/scala3
that referenced
this pull request
Feb 4, 2026
Change the synthetic hashCode for value classes from def hashCode(): Int = this.underlying.hashCode to def hashCode(): Int = java.util.Objects.hashCode(this.underlying) (unless the underlying value is primitive) Forward-port of scala/scala#11204 [Cherry-picked eb274c2]
tgodzik
pushed a commit
to scala/scala3-lts
that referenced
this pull request
Feb 17, 2026
Change the synthetic hashCode for value classes from def hashCode(): Int = this.underlying.hashCode to def hashCode(): Int = java.util.Objects.hashCode(this.underlying) (unless the underlying value is primitive) Forward-port of scala/scala#11204 [Cherry-picked eb274c2]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change the synthetic
hashCodefor value classes fromdef hashCode(): Int = this.underlying.hashCodeto
def hashCode(): Int = java.util.Objects.hashCode(this.underlying)(unless the underlying value is primitive)
Fixes scala/bug#7396