Skip to content

Commit 58fa2dd

Browse files
authored
Merge pull request #5226 from dotty-staging/repl-render-value
Use ScalaRunTime.replStringOf to render values in the REPL
2 parents 9d12693 + d825baf commit 58fa2dd

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.io.{ StringWriter, PrintWriter }
55
import java.lang.{ ClassLoader, ExceptionInInitializerError }
66
import java.lang.reflect.InvocationTargetException
77

8+
import scala.runtime.ScalaRunTime
89

910
import dotc.core.Contexts.Context
1011
import dotc.core.Denotations.Denotation
@@ -40,6 +41,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
4041
myClassLoader
4142
}
4243

44+
private[this] def MaxStringElements = 1000 // no need to mkString billions of elements
45+
4346
/** Load the value of the symbol using reflection.
4447
*
4548
* Calling this method evaluates the expression using reflection
@@ -52,12 +55,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
5255
resObj
5356
.getDeclaredMethods.find(_.getName == sym.name.encode.toString)
5457
.map(_.invoke(null))
55-
val string = value.map {
56-
case null => "null" // Calling .toString on null => NPE
57-
case "" => "\"\"" // Special cased for empty string, following scalac
58-
case a: Array[_] => a.mkString("Array(", ", ", ")")
59-
case x => x.toString
60-
}
58+
val string = value.map(ScalaRunTime.replStringOf(_, MaxStringElements).trim)
6159
if (!sym.is(Flags.Method) && sym.info == defn.UnitType)
6260
None
6361
else

0 commit comments

Comments
 (0)