Skip to content

Do not accidentally force diagnostic message in reportWarning #2348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/dotty/tools/dotc/reporting/TestReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 _ => ""
}
Expand Down Expand Up @@ -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)
Expand Down