Skip to content

Commit df22149

Browse files
authored
Merge pull request #2348 from dotty-staging/topic/cleanup-spree
Do not accidentally force diagnostic message in `reportWarning`
2 parents 5514655 + 69bbf85 commit df22149

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ class ConsoleReporter(
2424
def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
2525
val didPrint = m match {
2626
case m: Error =>
27-
printMessage(messageAndPos(m.contained, m.pos, diagnosticLevel(m)))
27+
printMessage(messageAndPos(m.contained(), m.pos, diagnosticLevel(m)))
2828
if (ctx.settings.prompt.value) displayPrompt()
2929
true
3030
case m: ConditionalWarning if !m.enablingOption.value =>
3131
false
3232
case m =>
33-
printMessage(messageAndPos(m.contained, m.pos, diagnosticLevel(m)))
33+
printMessage(messageAndPos(m.contained(), m.pos, diagnosticLevel(m)))
3434
true
3535
}
3636

3737
if (didPrint && ctx.shouldExplain(m))
38-
printMessage(explanation(m.contained))
39-
else if (didPrint && m.contained.explanation.nonEmpty)
38+
printMessage(explanation(m.contained()))
39+
else if (didPrint && m.contained().explanation.nonEmpty)
4040
printMessage("\nlonger explanation available when compiling with `-explain`")
4141
}
4242

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ trait Reporting { this: Context =>
3737
def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
3838
reporter.report(new Info(msg, pos))
3939

40-
def reportWarning(warning:Warning):Unit =
41-
if(this.settings.XfatalWarnings.value) error(warning.contained, warning.pos)
40+
def reportWarning(warning: Warning): Unit =
41+
if (this.settings.XfatalWarnings.value) reporter.report(warning.toError)
4242
else reporter.report(warning)
4343

4444
def deprecationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =

compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object MessageContainer {
1515
implicit class MessageContext(val c: Context) extends AnyVal {
1616
def shouldExplain(cont: MessageContainer): Boolean = {
1717
implicit val ctx = c
18-
cont.contained.explanation match {
18+
cont.contained().explanation match {
1919
case "" => false
2020
case _ => ctx.settings.explain.value
2121
}
@@ -39,7 +39,7 @@ class MessageContainer(
3939
/** The message to report */
4040
def message: String = {
4141
if (myMsg == null) {
42-
myMsg = contained.msg.replaceAll("\u001B\\[[;\\d]*m", "")
42+
myMsg = contained().msg.replaceAll("\u001B\\[[;\\d]*m", "")
4343
if (myMsg.contains(nonSensicalStartTag)) {
4444
myIsNonSensical = true
4545
// myMsg might be composed of several d"..." invocations -> nested
@@ -53,7 +53,8 @@ class MessageContainer(
5353
myMsg
5454
}
5555

56-
def contained: Message = {
56+
/** This function forces the contained message and returns it */
57+
def contained(): Message = {
5758
if (myContained == null)
5859
myContained = msgFn
5960

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ object messages {
3131
class Warning(
3232
msgFn: => Message,
3333
pos: SourcePosition
34-
) extends MessageContainer(msgFn, pos, WARNING)
34+
) extends MessageContainer(msgFn, pos, WARNING) {
35+
def toError: Error = new Error(msgFn, pos)
36+
}
3537

3638
class Info(
3739
msgFn: => Message,

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trait ErrorMessagesTest extends DottyTest {
4040

4141
def doReport(m: MessageContainer)(implicit ctx: Context) = {
4242
capturedContext = ctx
43-
buffer append m.contained
43+
buffer append m.contained()
4444
}
4545

4646
def toReport: Report =

compiler/test/dotty/tools/dotc/reporting/TestReporter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
4949

5050
/** Prints the message with the given position indication. */
5151
def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = {
52-
val msg = messageAndPos(m.contained, m.pos, diagnosticLevel(m))
52+
val msg = messageAndPos(m.contained(), m.pos, diagnosticLevel(m))
5353
val extraInfo = inlineInfo(m.pos)
5454

5555
if (m.level >= logLevel) {
@@ -63,7 +63,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
6363

6464
override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
6565
// Here we add extra information that we should know about the error message
66-
val extra = m.contained match {
66+
val extra = m.contained() match {
6767
case pm: PatternMatchExhaustivity => s": ${pm.uncovered}"
6868
case _ => ""
6969
}
@@ -120,7 +120,7 @@ object TestReporter {
120120
/** Prints the message with the given position indication in a simplified manner */
121121
override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = {
122122
def report() = {
123-
val msg = s"${m.pos.line + 1}: " + m.contained.kind + extra
123+
val msg = s"${m.pos.line + 1}: " + m.contained().kind + extra
124124
val extraInfo = inlineInfo(m.pos)
125125

126126
writer.println(msg)

0 commit comments

Comments
 (0)