Skip to content

Commit 065a002

Browse files
committed
Don't count suppressed errors
If an error message was supressed to count it in the total.
1 parent d4f30d1 commit 065a002

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class ConsoleReporter(
4040
}
4141
}
4242

43-
override def doReport(d: Diagnostic)(implicit ctx: Context): Unit =
44-
if (!d.isSuppressed || !hasErrors) d match {
43+
override def doReport(d: Diagnostic)(implicit ctx: Context): Boolean = {
44+
val issue = !(d.isSuppressed && hasErrors)
45+
if (issue) d match {
4546
case d: Error =>
4647
printMessageAndPos(s"error: ${d.msg}", d.pos)
4748
if (ctx.settings.prompt.value) displayPrompt()
@@ -51,6 +52,8 @@ class ConsoleReporter(
5152
case _ =>
5253
printMessageAndPos(d.msg, d.pos)
5354
}
55+
issue
56+
}
5457

5558
def displayPrompt(): Unit = {
5659
writer.print("\na)bort, s)tack, r)esume: ")

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ trait Reporting { this: Context =>
181181
*/
182182
abstract class Reporter {
183183

184-
/** Report a diagnostic */
185-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit
184+
/** Report a diagnostic, unless it is suppressed because it is nonsensical
185+
* @return a diagnostic was reported.
186+
*/
187+
def doReport(d: Diagnostic)(implicit ctx: Context): Boolean
186188

187189
/** Whether very long lines can be truncated. This exists so important
188190
* debugging information (like printing the classpath) is not rendered
@@ -220,16 +222,15 @@ abstract class Reporter {
220222
override def default(key: String) = 0
221223
}
222224

223-
def report(d: Diagnostic)(implicit ctx: Context): Unit = if (!isHidden(d)) {
224-
doReport(d)(ctx.addMode(Mode.Printing))
225-
d match {
226-
case d: ConditionalWarning if !d.enablingOption.value => unreportedWarnings(d.enablingOption.name) += 1
227-
case d: Warning => warningCount += 1
228-
case d: Error => errorCount += 1
229-
case d: Info => // nothing to do here
230-
// match error if d is something else
231-
}
232-
}
225+
def report(d: Diagnostic)(implicit ctx: Context): Unit =
226+
if (!isHidden(d) && doReport(d)(ctx.addMode(Mode.Printing)))
227+
d match {
228+
case d: ConditionalWarning if !d.enablingOption.value => unreportedWarnings(d.enablingOption.name) += 1
229+
case d: Warning => warningCount += 1
230+
case d: Error => errorCount += 1
231+
case d: Info => // nothing to do here
232+
// match error if d is something else
233+
}
233234

234235
def incomplete(d: Diagnostic)(implicit ctx: Context): Unit =
235236
incompleteHandler(d)(ctx)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ class StoreReporter(outer: Reporter) extends Reporter {
1414

1515
private var infos: mutable.ListBuffer[Diagnostic] = null
1616

17-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = {
17+
def doReport(d: Diagnostic)(implicit ctx: Context): Boolean = {
1818
typr.println(s">>>> StoredError: ${d.msg}") // !!! DEBUG
1919
if (infos == null) infos = new mutable.ListBuffer
2020
infos += d
21+
true
2122
}
2223

2324
override def hasPending: Boolean = infos != null && {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Reporter._
1111
* info to the underlying reporter.
1212
*/
1313
class ThrowingReporter(reportInfo: Reporter) extends Reporter {
14-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match {
14+
def doReport(d: Diagnostic)(implicit ctx: Context): Boolean = d match {
1515
case _: Error => throw d
1616
case _ => reportInfo.doReport(d)
1717
}

test/dotc/tests.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class tests extends CompilerTest {
109109
@Test def neg_privates() = compileFile(negDir, "privates", xerrors = 2)
110110
@Test def neg_rootImports = compileFile(negDir, "rootImplicits", xerrors = 2)
111111
@Test def neg_templateParents() = compileFile(negDir, "templateParents", xerrors = 3)
112-
@Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil, xerrors = 4)
113-
@Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 4)
112+
@Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil, xerrors = 3)
113+
@Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 3)
114114
@Test def neg_companions = compileFile(negDir, "companions", xerrors = 1)
115115
@Test def neg_over = compileFile(negDir, "over", xerrors = 3)
116116
@Test def neg_overrides = compileFile(negDir, "overrides", xerrors = 11)
@@ -145,6 +145,7 @@ class tests extends CompilerTest {
145145
@Test def neg_i583 = compileFile(negDir, "i0583-skolemize", xerrors = 2)
146146
@Test def neg_finalSealed = compileFile(negDir, "final-sealed", xerrors = 2)
147147
@Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7)
148+
@Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2)
148149
@Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)
149150
@Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)
150151
@Test def neg_instantiateAbstract = compileFile(negDir, "instantiateAbstract", xerrors = 8)

tests/neg/i866.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def x: Int = "" // error
3+
}
4+
import nonexistent._ // error; this one will swallow all errors below.
5+
object Foo {
6+
def bar(implicit x: NonExistent) = ???
7+
val baz = bar
8+
}
9+

0 commit comments

Comments
 (0)