Skip to content

Commit eabf647

Browse files
committed
print null result of replStringOf as null
[Cherry-picked 390d956][modified]
1 parent 8968458 commit eabf647

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
9999
val maxPrintElements = ctx.settings.VreplMaxPrintElements.valueIn(ctx.settingsState)
100100
val maxPrintCharacters = ctx.settings.VreplMaxPrintCharacters.valueIn(ctx.settingsState)
101101
// stringOf returns null if value.toString returns null. Show some text as a fallback.
102-
def toIdentityString(value: Object): String =
103-
s"${value.getClass.getName}@${System.identityHashCode(value).toHexString}"
104-
def fallback = s"""${toIdentityString(value)} // return value of "${sym.name}.toString" is null"""
102+
def fallback = s"""null // result of "${sym.name}.toString" is null"""
105103
if value == null then "null" else
106104
myReplStringOf(value, maxPrintElements, maxPrintCharacters) match
107105
case null => fallback

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,17 @@ class ReplCompilerTests extends ReplTest:
352352
run("val tpolecat = new Object { override def toString(): String = null }")
353353
.andThen:
354354
val last = lines().last
355-
assertTrue(last, last.startsWith("val tpolecat: Object = anon"))
356-
assertTrue(last, last.endsWith("""// return value of "tpolecat.toString" is null"""))
355+
assertTrue(last, last.startsWith("val tpolecat: Object = null"))
356+
assertTrue(last, last.endsWith("""// result of "tpolecat.toString" is null"""))
357357

358358
@Test def `i17333 print toplevel object with null toString`: Unit =
359359
initially:
360360
run("object tpolecat { override def toString(): String = null }")
361-
.andThen:
362-
run("tpolecat")
363-
val last = lines().last
364-
assertTrue(last, last.startsWith("val res0: tpolecat.type = tpolecat"))
365-
assertTrue(last, last.endsWith("""// return value of "res0.toString" is null"""))
366-
end ReplCompilerTests
361+
.andThen:
362+
run("tpolecat")
363+
val last = lines().last
364+
assertTrue(last, last.startsWith("val res0: tpolecat.type = null"))
365+
assertTrue(last, last.endsWith("""// result of "res0.toString" is null"""))
367366

368367
object ReplCompilerTests:
369368

0 commit comments

Comments
 (0)