Skip to content

Commit ef4c430

Browse files
authored
Merge pull request #4200 from bhop/feature/show-instance-for-arrays
Fix #4067 dotty REPL shows the Array hexcode instead of actual elements
2 parents fe8386d + 053810e commit ef4c430

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

library/src/dotty/Show.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ object Show extends LowPrioShow {
5858
else "List(" + xs.map(_.show).mkString(", ") + ")"
5959
}
6060

61+
implicit def arrayShow[T](implicit st: Show[T]): Show[Array[T]] = new Show[Array[T]] {
62+
def show(xs: Array[T]): String =
63+
if (xs.isEmpty) "Array()"
64+
else "Array(" + xs.map(_.show).mkString(", ") + ")"
65+
}
66+
6167
implicit def showOption[T](implicit st: Show[T]): Show[Option[T]] = new Show[Option[T]] {
6268
def show(ot: Option[T]): String = ot match {
6369
case Some(t) => "Some("+ st.show(t) + ")"

library/test/dotty/ShowTests.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ class ShowTests {
7373
case object Foo
7474
assertEquals("Map(Foo -> \"Hello\")", Map(Foo -> "Hello").show)
7575
}
76+
77+
@Test def showArrays = {
78+
assertEquals("Array()", Array[Int]().show)
79+
assertEquals("Array(1)", Array(1).show)
80+
assertEquals("Array(1, 2, 3)", Array(1, 2, 3).show)
81+
}
7682
}

0 commit comments

Comments
 (0)