Skip to content

Commit e5ed401

Browse files
committed
Fixes now that explicit nulls are on
1 parent 579e14b commit e5ed401

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ object Decorators {
249249
extension [T](x: T)
250250
def showing[U](
251251
op: WrappedResult[U] ?=> String,
252-
printer: config.Printers.Printer = config.Printers.default)(using c: Conversion[T, U] = null): T = {
252+
printer: config.Printers.Printer = config.Printers.default)(using c: Conversion[T, U] | Null = null): T = {
253253
// either the use of `$result` was driven by the expected type of `Shown`
254254
// which led to the summoning of `Conversion[T, Shown]` (which we'll invoke)
255255
// or no such conversion was found so we'll consume the result as it is instead
@@ -268,7 +268,7 @@ object Decorators {
268268
if !ctx.mode.is(Mode.PrintShowExceptions) && !ctx.settings.YshowPrintErrors.value =>
269269
val msg = ex match { case te: TypeError => te.toMessage case _ => ex.getMessage }
270270
s"[cannot display due to $msg, raw string = $x]"
271-
case _ => String.valueOf(x)
271+
case _ => String.valueOf(x).nn
272272

273273
extension [T](x: T)
274274
def assertingErrorsReported(using Context): T = {

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ object Formatting {
5050
given [A: Show, B: Show]: Show[(A, B)] with
5151
def show(x: (A, B)) = (Show[A].show(x._1), Show[B].show(x._2))
5252

53+
given [X: Show]: Show[X | Null] with
54+
def show(x: X | Null) = if x == null then "null" else Show[X].show(x.nn)
55+
5356
given Show[FlagSet] with
5457
def show(x: FlagSet) = x.flagsString
5558

0 commit comments

Comments
 (0)