diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index 22500cbbaa48..237a3f166fe8 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -15,6 +15,7 @@ import java.io.{BufferedReader, PrintWriter} import scala.annotation.internal.sharable import scala.collection.mutable import core.Decorators.em +import core.handleRecursive object Reporter { /** Convert a SimpleReporter into a real Reporter */ @@ -155,6 +156,12 @@ abstract class Reporter extends interfaces.ReporterResult { addUnreported(key, 1) case _ => if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced + try + withMode(Mode.Printing)(doReport(dia)) + catch case ex: Throwable => + // #20158: Don't increment the error count, otherwise we might suppress + // the RecursiveOverflow error and not print any error at all. + handleRecursive("error reporting", dia.message, ex) dia match { case w: Warning => warnings = w :: warnings @@ -168,7 +175,6 @@ abstract class Reporter extends interfaces.ReporterResult { // match error if d is something else } markReported(dia) - withMode(Mode.Printing)(doReport(dia)) end issueUnconfigured def issueIfNotSuppressed(dia: Diagnostic)(using Context): Unit = diff --git a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala index a96a2765d56a..3b30742a8d4f 100644 --- a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala @@ -71,8 +71,8 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M } if dia.level >= WARNING then - _diagnosticBuf.append(dia) _consoleReporter.doReport(dia) + _diagnosticBuf.append(dia) printMessageAndPos(dia, extra) } } diff --git a/tests/neg/mt-deskolemize.scala b/tests/neg/mt-deskolemize.scala new file mode 100644 index 000000000000..0a58d5db7bc4 --- /dev/null +++ b/tests/neg/mt-deskolemize.scala @@ -0,0 +1,16 @@ +trait Expr: + type Value +object Expr: + type Of[V] = Expr { type Value = V } + type ExtractValue[F <: Expr] = F match + case Expr.Of[v] => v +import Expr.ExtractValue + +class SimpleLoop1 extends Expr: + type Value = ExtractValue[SimpleLoop2] + +class SimpleLoop2 extends Expr: + type Value = ExtractValue[SimpleLoop1] + +object Test1: + val x: ExtractValue[SimpleLoop1] = 1 // error