Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.
  • Loading branch information
lihaoyi committed Sep 1, 2025
commit c7d109bf84030db0181a0fd04317b17c5118fad3
15 changes: 1 addition & 14 deletions compiler/src/dotty/tools/repl/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):

var myClassLoader: AbstractFileClassLoader = uninitialized

/** (value, maxElements, maxCharacters) => String */
val myReplStringOf: (Object, Int, Int) => String =
dotty.shaded.pprint.PPrinter.BlackWhite.apply(value).plainText

/** Class loader used to load compiled code */
private[repl] def classLoader()(using Context) =
Expand Down Expand Up @@ -57,17 +54,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):

/** Return a String representation of a value we got from `classLoader()`. */
private[repl] def replStringOf(sym: Symbol, value: Object)(using Context): String =
assert(myReplStringOf != null,
"replStringOf should only be called on values creating using `classLoader()`, but `classLoader()` has not been called so far")
val maxPrintElements = ctx.settings.VreplMaxPrintElements.valueIn(ctx.settingsState)
val maxPrintCharacters = ctx.settings.VreplMaxPrintCharacters.valueIn(ctx.settingsState)
// stringOf returns null if value.toString returns null. Show some text as a fallback.
def fallback = s"""null // result of "${sym.name}.toString" is null"""
if value == null then "null" else
myReplStringOf(value, maxPrintElements, maxPrintCharacters) match
case null => fallback
case res => res
end if
dotty.shaded.pprint.PPrinter.BlackWhite.apply(value).plainText

/** Load the value of the symbol using reflection.
*
Expand Down
2 changes: 0 additions & 2 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ class ReplCompilerTests extends ReplTest:
.andThen:
val last = lines().last
assertTrue(last, last.startsWith("val tpolecat: Object = null"))
assertTrue(last, last.endsWith("""// result of "tpolecat.toString" is null"""))

@Test def `i17333 print toplevel object with null toString`: Unit =
initially:
Expand All @@ -454,7 +453,6 @@ class ReplCompilerTests extends ReplTest:
run("tpolecat")
val last = lines().last
assertTrue(last, last.startsWith("val res0: tpolecat.type = null"))
assertTrue(last, last.endsWith("""// result of "res0.toString" is null"""))

@Test def `i21431 filter out best effort options`: Unit =
initially:
Expand Down
Loading