Skip to content

Commit b9e03b8

Browse files
committed
Remove unnecessary printing of hints for -explain
1 parent 45a2df1 commit b9e03b8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ object Formatting {
9090
}
9191
}
9292

93-
private def wrapNonSensical(arg: Any, str: String)(implicit ctx: Context): String = {
93+
private def wrapNonSensical(arg: Any /* Type | Symbol */, str: String)(implicit ctx: Context): String = {
9494
import MessageContainer._
9595
def isSensical(arg: Any): Boolean = arg match {
9696
case tpe: Type =>

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ConsoleReporter(
9494
}).show else ""
9595

9696
/** Prints the message with the given position indication. */
97-
def printMessageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(implicit ctx: Context): Unit = {
97+
def printMessageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(implicit ctx: Context): Boolean = {
9898
printMessage(posStr(pos, diagnosticLevel, msg))
9999
if (pos.exists) {
100100
val (srcBefore, srcAfter, offset) = sourceLines(pos)
@@ -103,6 +103,7 @@ class ConsoleReporter(
103103

104104
printMessage((srcBefore ::: marker :: err :: srcAfter).mkString("\n"))
105105
} else printMessage(msg.msg)
106+
true
106107
}
107108

108109
def printExplanation(m: Message)(implicit ctx: Context): Unit = {
@@ -114,11 +115,13 @@ class ConsoleReporter(
114115
}
115116

116117
override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
117-
m match {
118+
val didPrint = m match {
118119
case m: Error =>
119-
printMessageAndPos(m.contained, m.pos, "Error")
120+
val didPrint = printMessageAndPos(m.contained, m.pos, "Error")
120121
if (ctx.settings.prompt.value) displayPrompt()
122+
didPrint
121123
case m: ConditionalWarning if !m.enablingOption.value =>
124+
false
122125
case m: FeatureWarning =>
123126
printMessageAndPos(m.contained, m.pos, "Feature Warning")
124127
case m: DeprecationWarning =>
@@ -133,9 +136,9 @@ class ConsoleReporter(
133136
printMessageAndPos(m.contained, m.pos, "Info")
134137
}
135138

136-
if (ctx.shouldExplain(m))
139+
if (didPrint && ctx.shouldExplain(m))
137140
printExplanation(m.contained)
138-
else if (m.contained.explanation.nonEmpty)
141+
else if (didPrint && m.contained.explanation.nonEmpty)
139142
printMessage("\nlonger explanation available when compiling with `-explain`")
140143
}
141144

0 commit comments

Comments
 (0)