Skip to content

Commit 52d6c1b

Browse files
Backport "Make error reporting resilient to exception thrown while reporting" to LTS (#21059)
Backports #20158 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents c8b0325 + cf74996 commit 52d6c1b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import java.io.{BufferedReader, PrintWriter}
1515
import scala.annotation.internal.sharable
1616
import scala.collection.mutable
1717
import core.Decorators.em
18+
import core.handleRecursive
1819

1920
object Reporter {
2021
/** Convert a SimpleReporter into a real Reporter */
@@ -155,6 +156,12 @@ abstract class Reporter extends interfaces.ReporterResult {
155156
addUnreported(key, 1)
156157
case _ =>
157158
if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced
159+
try
160+
withMode(Mode.Printing)(doReport(dia))
161+
catch case ex: Throwable =>
162+
// #20158: Don't increment the error count, otherwise we might suppress
163+
// the RecursiveOverflow error and not print any error at all.
164+
handleRecursive("error reporting", dia.message, ex)
158165
dia match {
159166
case w: Warning =>
160167
warnings = w :: warnings
@@ -168,7 +175,6 @@ abstract class Reporter extends interfaces.ReporterResult {
168175
// match error if d is something else
169176
}
170177
markReported(dia)
171-
withMode(Mode.Printing)(doReport(dia))
172178
end issueUnconfigured
173179

174180
def issueIfNotSuppressed(dia: Diagnostic)(using Context): Unit =

compiler/test/dotty/tools/dotc/reporting/TestReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
7070
}
7171

7272
if dia.level >= WARNING then
73-
_diagnosticBuf.append(dia)
7473
_consoleReporter.doReport(dia)
74+
_diagnosticBuf.append(dia)
7575
printMessageAndPos(dia, extra)
7676
}
7777
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// LTS specific change: -Yno-deep-subtypes makes it crash, in Next is placed in neg/
2+
trait Expr:
3+
type Value
4+
object Expr:
5+
type Of[V] = Expr { type Value = V }
6+
type ExtractValue[F <: Expr] = F match
7+
case Expr.Of[v] => v
8+
import Expr.ExtractValue
9+
10+
class SimpleLoop1 extends Expr:
11+
type Value = ExtractValue[SimpleLoop2]
12+
13+
class SimpleLoop2 extends Expr:
14+
type Value = ExtractValue[SimpleLoop1]
15+
16+
object Test1:
17+
val x: ExtractValue[SimpleLoop1] = 1 // error

0 commit comments

Comments
 (0)