Skip to content

Commit b9c6290

Browse files
committed
Fix NPE for any type of show
1 parent df7c559 commit b9c6290

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compiler/test-resources/repl/i4301

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
scala> List(null)
22
val res0: List[Null] = List(null)
3+
scala> List[String](null)
4+
val res1: List[String] = List(null)

library/src/dotty/Show.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait Show[T] {
66

77
trait LowPrioShow {
88
implicit def defaultShow[T]: Show[T] = new Show[T] {
9-
def show(x: T) = if (x == null) "null" else x.toString
9+
def show(x: T) = x.toString
1010
}
1111
}
1212

@@ -16,8 +16,7 @@ object Show extends LowPrioShow {
1616
* any `T`, we default to `T#toString`.
1717
*/
1818
implicit class ShowValue[V](val v: V) extends AnyVal {
19-
def show(implicit ev: Show[V]): String =
20-
ev.show(v)
19+
def show(implicit ev: Show[V]): String = if (v == null) "null" else ev.show(v)
2120
}
2221

2322
/** Adds escaping backslashes in a string so that it could be put in source code.

0 commit comments

Comments
 (0)