Skip to content

Commit 31165f2

Browse files
committed
Call hasErrors first but then bump before doReport
We can switch to a more straightforward hasErrors check in isHidden, but then we need to bump the errorCount before calling doReport, as doReport will then, necessarily, force the message. For reference, the way I test this manually is by: 1. In ignoredConvertibleImplicits, changing back to `viewExists(imp, fail.expectedType)` 2. In adapt1, removing the `dummyTreeOfType.unapply(tree).isEmpty` guard 3. Compiling tests/neg/i18650.scala Also, while I'm here, instruct on the presence of -Yno-enrich-error-messages, like we do for -Yno-decode-stacktraces.
1 parent 4fb8e7c commit 31165f2

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

compiler/src/dotty/tools/dotc/report.scala

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ object report:
155155
| An unhandled exception was thrown in the compiler.
156156
| Please file a crash report here:
157157
| https://github.com/lampepfl/dotty/issues/new/choose
158+
| For non-enriched exceptions, compile with -Yno-enrich-error-messages.
158159
|
159160
|$info1
160161
|""".stripMargin

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

+3-14
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,8 @@ trait HideNonSensicalMessages extends Reporter {
1313
*/
1414
override def isHidden(dia: Diagnostic)(using Context): Boolean =
1515
super.isHidden(dia) || {
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) &&
28-
hasErrors && // if there are no errors yet, report even if diagnostic is non-sensical
29-
!ctx.settings.YshowSuppressedErrors.value
16+
hasErrors // if there are no errors yet, report even if diagnostic is non-sensical
17+
&& dia.msg.isNonSensical // defer forcing the message by calling hasErrors first
18+
&& !ctx.settings.YshowSuppressedErrors.value
3019
}
3120
}

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

+4-4
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-
protected var _errorCount = 0
96-
protected var _warningCount = 0
95+
private var _errorCount = 0
96+
private var _warningCount = 0
9797

9898
/** The number of errors reported by this reporter (ignoring outer reporters) */
9999
def errorCount: Int = _errorCount
@@ -155,8 +155,6 @@ abstract class Reporter extends interfaces.ReporterResult {
155155
addUnreported(key, 1)
156156
case _ =>
157157
if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced
158-
markReported(dia)
159-
withMode(Mode.Printing)(doReport(dia))
160158
dia match {
161159
case w: Warning =>
162160
warnings = w :: warnings
@@ -169,6 +167,8 @@ abstract class Reporter extends interfaces.ReporterResult {
169167
case _: Info => // nothing to do here
170168
// match error if d is something else
171169
}
170+
markReported(dia)
171+
withMode(Mode.Printing)(doReport(dia))
172172
end issueUnconfigured
173173

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

0 commit comments

Comments
 (0)