Skip to content

Commit ec958ac

Browse files
Special case .toString on Arrays
1 parent cfcc624 commit ec958ac

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,23 @@ private[repl] class Rendering(compiler: ReplCompiler,
5353
val resObj: Class[_] = Class.forName(objectName, true, classLoader())
5454
val value =
5555
resObj
56-
.getDeclaredMethods.find(_.getName == sym.name.encode.toString).get
57-
.invoke(null)
58-
val string = value match {
59-
case null => "null" // Calling .toString on null => NPE
60-
case "" => "\"\"" // Sepcial cased for empty string, following scalac
61-
case x => x.toString
56+
.getDeclaredMethods.find(_.getName == sym.name.encode.toString)
57+
.map(_.invoke(null))
58+
val string = value.map {
59+
case null => "null" // Calling .toString on null => NPE
60+
case "" => "\"\"" // Special cased for empty string, following scalac
61+
case a: Array[_] => a.mkString("Array(", ", ", ")")
62+
case x => x.toString
6263
}
6364
if (!sym.is(Flags.Method) && sym.info == defn.UnitType)
6465
None
65-
else if (string.startsWith(str.REPL_SESSION_LINE))
66-
Some(string.drop(str.REPL_SESSION_LINE.length).dropWhile(c => c.isDigit || c == '$'))
6766
else
68-
Some(string)
67+
string.map { s =>
68+
if (s.startsWith(str.REPL_SESSION_LINE))
69+
s.drop(str.REPL_SESSION_LINE.length).dropWhile(c => c.isDigit || c == '$')
70+
else
71+
s
72+
}
6973
}
7074

7175
/** Render method definition result */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scala> val a = Array(1, 2, 3)
2+
val a: Array[Int] = Array(1, 2, 3)

0 commit comments

Comments
 (0)