Skip to content

Fix #4067 dotty REPL shows the Array hexcode instead of actual elements #4200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions library/src/dotty/Show.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ object Show extends LowPrioShow {
else "List(" + xs.map(_.show).mkString(", ") + ")"
}

implicit def arrayShow[T](implicit st: Show[T]): Show[Array[T]] = new Show[Array[T]] {
def show(xs: Array[T]): String =
if (xs.isEmpty) "Array()"
else "Array(" + xs.map(_.show).mkString(", ") + ")"
}

implicit def showOption[T](implicit st: Show[T]): Show[Option[T]] = new Show[Option[T]] {
def show(ot: Option[T]): String = ot match {
case Some(t) => "Some("+ st.show(t) + ")"
Expand Down
6 changes: 6 additions & 0 deletions library/test/dotty/ShowTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@ class ShowTests {
case object Foo
assertEquals("Map(Foo -> \"Hello\")", Map(Foo -> "Hello").show)
}

@Test def showArrays = {
assertEquals("Array()", Array[Int]().show)
assertEquals("Array(1)", Array(1).show)
assertEquals("Array(1, 2, 3)", Array(1, 2, 3).show)
}
}