diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index bea42e82ce6f..39dccf3d0c87 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -628,7 +628,7 @@ class Inliner(val call: tpd.Tree)(using Context): // The context in which we report should still use the existing context reporter val ctxOrigReporter = ctxToReport.fresh.setReporter(ctx.reporter) inContext(ctxOrigReporter) { - report.error(message, callToReport.srcPos) + report.error(new reporting.Custom(message), callToReport.srcPos) } case _ => } diff --git a/compiler/src/dotty/tools/dotc/reporting/Message.scala b/compiler/src/dotty/tools/dotc/reporting/Message.scala index 77e1336a990c..267029ead8c5 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Message.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Message.scala @@ -149,6 +149,15 @@ abstract class Message(val errorId: ErrorMessageID) { self => override def toString = msg } +/* a message generated by an inlined call to compiletime.error method */ +class Custom(_msg: String) extends Message(ErrorMessageID.NoExplanationID) { + def msg: String = _msg + def explain: String = "" + val kind: MessageKind = MessageKind.CustomCompiletime + + override def toString(): String = msg +} + /** The fallback `Message` containing no explanation and having no `kind` */ class NoExplanation(msgFn: => String) extends Message(ErrorMessageID.NoExplanationID) { def msg: String = msgFn diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageKind.scala b/compiler/src/dotty/tools/dotc/reporting/MessageKind.scala index f039ed900a76..7ef3bfa7e2c3 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageKind.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageKind.scala @@ -21,6 +21,7 @@ enum MessageKind: case MatchCaseUnreachable case Compatibility case PotentialIssue + case CustomCompiletime /** Human readable message that will end up being shown to the user. * NOTE: This is only used in the situation where you have multiple words diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala index f53359fb8b19..a65a8a382675 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala @@ -187,7 +187,7 @@ trait MessageRendering { s"[E${"0" * (3 - errorNumber.toString.length) + errorNumber}] " else "" val kind = - if (message.kind == MessageKind.NoKind) then diagnosticString + if (message.kind == MessageKind.NoKind || message.kind == MessageKind.CustomCompiletime) then diagnosticString else s"${message.kind.message} $diagnosticString" val title = if fileAndPos.isEmpty then s"$errId$kind:" // this happens in dotty.tools.repl.ScriptedTests // TODO add name of source or remove `:` (and update test files) diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index e8e49071bf2b..184b872f0103 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -1127,7 +1127,7 @@ trait Implicits: case _ => tryConversion } - if ctx.reporter.hasErrors + if (ctx.reporter.hasErrors && ctx.reporter.allErrors.exists(_.msg.kind != MessageKind.CustomCompiletime)) || !cand.ref.symbol.isAccessibleFrom(cand.ref.prefix) then ctx.reporter.removeBufferedMessages