diff --git a/compiler/src/dotty/tools/dotc/core/TyperState.scala b/compiler/src/dotty/tools/dotc/core/TyperState.scala index 9aa51a6714c3..6163eebfbef4 100644 --- a/compiler/src/dotty/tools/dotc/core/TyperState.scala +++ b/compiler/src/dotty/tools/dotc/core/TyperState.scala @@ -103,7 +103,7 @@ class TyperState() { this /** A fresh typer state with the same constraint as this one. */ - def fresh(reporter: Reporter = StoreReporter(this.reporter), + def fresh(reporter: Reporter = StoreReporter(this.reporter, fromTyperState = true), committable: Boolean = this.isCommittable): TyperState = util.Stats.record("TyperState.fresh") TyperState().init(this, this.constraint) diff --git a/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala b/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala index e7b636cddf02..9255820140d8 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala @@ -7,7 +7,7 @@ import core.Contexts.Context import Diagnostic._ /** A re-usable Reporter used in Contexts#test */ -class ExploringReporter extends StoreReporter(null): +class ExploringReporter extends StoreReporter(null, fromTyperState = false): infos = new mutable.ListBuffer[Diagnostic] override def hasUnreportedErrors: Boolean = diff --git a/compiler/src/dotty/tools/dotc/reporting/StoreReporter.scala b/compiler/src/dotty/tools/dotc/reporting/StoreReporter.scala index d3c334599666..87255a48eab5 100644 --- a/compiler/src/dotty/tools/dotc/reporting/StoreReporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/StoreReporter.scala @@ -17,7 +17,7 @@ import Diagnostic._ * - The reporter is not flushed and the message containers capture a * `Context` (about 4MB) */ -class StoreReporter(outer: Reporter = Reporter.NoReporter) extends Reporter { +class StoreReporter(outer: Reporter = Reporter.NoReporter, fromTyperState: Boolean = false) extends Reporter { protected var infos: mutable.ListBuffer[Diagnostic] = null @@ -40,4 +40,11 @@ class StoreReporter(outer: Reporter = Reporter.NoReporter) extends Reporter { override def pendingMessages(using Context): List[Diagnostic] = if (infos != null) infos.toList else Nil override def errorsReported: Boolean = hasErrors || (outer != null && outer.errorsReported) + + // If this is a TyperState buffering reporter then buffer the messages, + // so that then only when the messages are unbuffered (when the reporter if flushed) + // do they go through -Wconf, and possibly then buffered on the Run as a suspended message + override def report(dia: Diagnostic)(using Context): Unit = + if fromTyperState then doReport(dia) + else super.report(dia) } diff --git a/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala index 8ad5b525de5c..a3d84e462bf0 100644 --- a/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala @@ -6,7 +6,7 @@ import collection.mutable import Diagnostic._ /** A re-usable Reporter used in Contexts#test */ -class TestingReporter extends StoreReporter(null): +class TestingReporter extends StoreReporter(null, fromTyperState = false): infos = new mutable.ListBuffer[Diagnostic] override def hasUnreportedErrors: Boolean = infos.exists(_.isInstanceOf[Error]) def reset(): Unit = infos.clear()