Skip to content

Commit 6d877d1

Browse files
dwijnandWojciechMazur
authored andcommitted
Move faking errors to HideNonSensicalMessages
Because HideNonSensicalMessages looks at hasErrors, we need to narrow the faking to just the isNonSensical call [Cherry-picked 4fb8e7c]
1 parent 85c5be3 commit 6d877d1

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ trait HideNonSensicalMessages extends Reporter {
1313
*/
1414
override def isHidden(dia: Diagnostic)(using Context): Boolean =
1515
super.isHidden(dia) || {
16-
dia.msg.isNonSensical &&
16+
(if !errorsReported && dia.isInstanceOf[Diagnostic.Error] then
17+
// Bump up errorCount so hasErrors is true while forcing the message.
18+
// We use errorsReported as a predicate for broken code.
19+
// So now any forcing won't cause, for instance,
20+
// assertion errors and thus compiler crashes.
21+
// Some messages, once forced, run more code
22+
// to generate useful hints for the user.
23+
try
24+
_errorCount += 1
25+
dia.msg.isNonSensical
26+
finally _errorCount -= 1 // decrease rather than reset the value so we only ever decrease by 1
27+
else dia.msg.isNonSensical) &&
1728
hasErrors && // if there are no errors yet, report even if diagnostic is non-sensical
1829
!ctx.settings.YshowSuppressedErrors.value
1930
}

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ abstract class Reporter extends interfaces.ReporterResult {
9292

9393
private def isIncompleteChecking = incompleteHandler ne defaultIncompleteHandler
9494

95-
private var _errorCount = 0
96-
private var _warningCount = 0
95+
protected var _errorCount = 0
96+
protected var _warningCount = 0
9797

9898
/** The number of errors reported by this reporter (ignoring outer reporters) */
9999
def errorCount: Int = _errorCount
@@ -154,20 +154,7 @@ abstract class Reporter extends interfaces.ReporterResult {
154154
val key = w.enablingOption.name
155155
addUnreported(key, 1)
156156
case _ =>
157-
val hide = if !errorsReported && dia.isInstanceOf[Error] then
158-
// We bump up errorCount so errorsReported is true while executing isHidden.
159-
// We use errorsReported as a predicate for broken code.
160-
// So now any code `isHidden` runs won't cause, for instance,
161-
// assertion errors and thus compiler crashes.
162-
// This normally amounts to forcing the message, which might run more code
163-
// to generate useful hints for the user.
164-
try
165-
_errorCount += 1
166-
isHidden(dia)
167-
finally
168-
_errorCount -= 1 // decrease rather than set back to `oldErrorCount` so we only ever decrease by 1
169-
else isHidden(dia)
170-
if !hide then // avoid isHidden test for summarized warnings so that message is not forced
157+
if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced
171158
markReported(dia)
172159
withMode(Mode.Printing)(doReport(dia))
173160
dia match {

0 commit comments

Comments
 (0)