diff --git a/compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index 9942b9ab9822..dbaa68f30fda 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -24,19 +24,19 @@ class ConsoleReporter( def doReport(m: MessageContainer)(implicit ctx: Context): Unit = { val didPrint = m match { case m: Error => - printMessage(messageAndPos(m.contained, m.pos, diagnosticLevel(m))) + printMessage(messageAndPos(m.contained(), m.pos, diagnosticLevel(m))) if (ctx.settings.prompt.value) displayPrompt() true case m: ConditionalWarning if !m.enablingOption.value => false case m => - printMessage(messageAndPos(m.contained, m.pos, diagnosticLevel(m))) + printMessage(messageAndPos(m.contained(), m.pos, diagnosticLevel(m))) true } if (didPrint && ctx.shouldExplain(m)) - printMessage(explanation(m.contained)) - else if (didPrint && m.contained.explanation.nonEmpty) + printMessage(explanation(m.contained())) + else if (didPrint && m.contained().explanation.nonEmpty) printMessage("\nlonger explanation available when compiling with `-explain`") } diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index f3409bcd9d2d..dd32e9335ca9 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -37,8 +37,8 @@ trait Reporting { this: Context => def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = reporter.report(new Info(msg, pos)) - def reportWarning(warning:Warning):Unit = - if(this.settings.XfatalWarnings.value) error(warning.contained, warning.pos) + def reportWarning(warning: Warning): Unit = + if (this.settings.XfatalWarnings.value) reporter.report(warning.toError) else reporter.report(warning) def deprecationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala index c27644ad9956..9884fdb1d1c8 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala @@ -15,7 +15,7 @@ object MessageContainer { implicit class MessageContext(val c: Context) extends AnyVal { def shouldExplain(cont: MessageContainer): Boolean = { implicit val ctx = c - cont.contained.explanation match { + cont.contained().explanation match { case "" => false case _ => ctx.settings.explain.value } @@ -39,7 +39,7 @@ class MessageContainer( /** The message to report */ def message: String = { if (myMsg == null) { - myMsg = contained.msg.replaceAll("\u001B\\[[;\\d]*m", "") + myMsg = contained().msg.replaceAll("\u001B\\[[;\\d]*m", "") if (myMsg.contains(nonSensicalStartTag)) { myIsNonSensical = true // myMsg might be composed of several d"..." invocations -> nested @@ -53,7 +53,8 @@ class MessageContainer( myMsg } - def contained: Message = { + /** This function forces the contained message and returns it */ + def contained(): Message = { if (myContained == null) myContained = msgFn diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 20cd0842669c..b3c49a333822 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -31,7 +31,9 @@ object messages { class Warning( msgFn: => Message, pos: SourcePosition - ) extends MessageContainer(msgFn, pos, WARNING) + ) extends MessageContainer(msgFn, pos, WARNING) { + def toError: Error = new Error(msgFn, pos) + } class Info( msgFn: => Message, diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala index 9be98ee65f04..6ea4d0abe7c5 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala @@ -40,7 +40,7 @@ trait ErrorMessagesTest extends DottyTest { def doReport(m: MessageContainer)(implicit ctx: Context) = { capturedContext = ctx - buffer append m.contained + buffer append m.contained() } def toReport: Report = diff --git a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala index 664526c98161..33b66311aa30 100644 --- a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala @@ -49,7 +49,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M /** Prints the message with the given position indication. */ def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = { - val msg = messageAndPos(m.contained, m.pos, diagnosticLevel(m)) + val msg = messageAndPos(m.contained(), m.pos, diagnosticLevel(m)) val extraInfo = inlineInfo(m.pos) if (m.level >= logLevel) { @@ -63,7 +63,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = { // Here we add extra information that we should know about the error message - val extra = m.contained match { + val extra = m.contained() match { case pm: PatternMatchExhaustivity => s": ${pm.uncovered}" case _ => "" } @@ -120,7 +120,7 @@ object TestReporter { /** Prints the message with the given position indication in a simplified manner */ override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = { def report() = { - val msg = s"${m.pos.line + 1}: " + m.contained.kind + extra + val msg = s"${m.pos.line + 1}: " + m.contained().kind + extra val extraInfo = inlineInfo(m.pos) writer.println(msg)