diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index 9dd987779843..89f533dc10bd 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -17,7 +17,8 @@ import config.Printers.cyclicErrors class TypeError(msg: String) extends Exception(msg) { def this() = this("") - def toMessage(implicit ctx: Context): Message = getMessage + def toMessage(implicit ctx: Context): Message = super.getMessage + override def getMessage: String = throw new Exception("Use toMessage instead for TypeError") } class MalformedType(pre: Type, denot: Denotation, absMembers: Set[Name]) extends TypeError { diff --git a/compiler/src/dotty/tools/dotc/printing/Formatting.scala b/compiler/src/dotty/tools/dotc/printing/Formatting.scala index 7c2150736969..5473978f0de0 100644 --- a/compiler/src/dotty/tools/dotc/printing/Formatting.scala +++ b/compiler/src/dotty/tools/dotc/printing/Formatting.scala @@ -31,7 +31,8 @@ object Formatting { case NonFatal(ex) if !ctx.mode.is(Mode.PrintShowExceptions) && !ctx.settings.YshowPrintErrors.value => - s"[cannot display due to $ex, raw string = ${arg.toString}]" + val msg = ex match { case te: TypeError => te.toMessage case _ => ex.getMessage } + s"[cannot display due to $msg, raw string = ${arg.toString}]" } case _ => arg.toString } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 7df6a573c65a..80bf00a95753 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -982,7 +982,7 @@ class RefChecks extends MiniPhase { thisPhase => tree } catch { case ex: TypeError => - ctx.error(ex.getMessage, tree.sourcePos) + ctx.error(ex.toMessage, tree.sourcePos) tree }