Skip to content

Commit 390d956

Browse files
committed
print null result of replStringOf as null
1 parent 302aaca commit 390d956

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

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

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,17 @@ class ReplCompilerTests extends ReplTest:
436436
run("val tpolecat = new Object { override def toString(): String = null }")
437437
.andThen:
438438
val last = lines().last
439-
assertTrue(last, last.startsWith("val tpolecat: Object = anon"))
440-
assertTrue(last, last.endsWith("""// return value of "tpolecat.toString" is null"""))
439+
assertTrue(last, last.startsWith("val tpolecat: Object = null"))
440+
assertTrue(last, last.endsWith("""// result of "tpolecat.toString" is null"""))
441441

442442
@Test def `i17333 print toplevel object with null toString`: Unit =
443443
initially:
444444
run("object tpolecat { override def toString(): String = null }")
445445
.andThen:
446446
run("tpolecat")
447447
val last = lines().last
448-
assertTrue(last, last.startsWith("val res0: tpolecat.type = tpolecat"))
449-
assertTrue(last, last.endsWith("""// return value of "res0.toString" is null"""))
448+
assertTrue(last, last.startsWith("val res0: tpolecat.type = null"))
449+
assertTrue(last, last.endsWith("""// result of "res0.toString" is null"""))
450450

451451
object ReplCompilerTests:
452452

0 commit comments

Comments
 (0)