Skip to content

Commit 47c51dd

Browse files
Merge pull request #5832 from dotty-staging/fix-missing-message
Fix missing error message
2 parents 4418821 + 00fbf27 commit 47c51dd

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import config.Printers.cyclicErrors
1717

1818
class TypeError(msg: String) extends Exception(msg) {
1919
def this() = this("")
20-
def toMessage(implicit ctx: Context): Message = getMessage
20+
def toMessage(implicit ctx: Context): Message = super.getMessage
21+
override def getMessage: String = throw new Exception("Use toMessage instead for TypeError")
2122
}
2223

2324
class MalformedType(pre: Type, denot: Denotation, absMembers: Set[Name]) extends TypeError {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ object Formatting {
3131
case NonFatal(ex)
3232
if !ctx.mode.is(Mode.PrintShowExceptions) &&
3333
!ctx.settings.YshowPrintErrors.value =>
34-
s"[cannot display due to $ex, raw string = ${arg.toString}]"
34+
val msg = ex match { case te: TypeError => te.toMessage case _ => ex.getMessage }
35+
s"[cannot display due to $msg, raw string = ${arg.toString}]"
3536
}
3637
case _ => arg.toString
3738
}

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ class RefChecks extends MiniPhase { thisPhase =>
982982
tree
983983
} catch {
984984
case ex: TypeError =>
985-
ctx.error(ex.getMessage, tree.sourcePos)
985+
ctx.error(ex.toMessage, tree.sourcePos)
986986
tree
987987
}
988988

0 commit comments

Comments
 (0)