Skip to content

Commit 06d518d

Browse files
committed
Make fatal warnings not fail compilation early & aggregate warns
1 parent 6d759fb commit 06d518d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
346346
runCtx.withProgressCallback: cb =>
347347
_progress = Progress(cb, this, fusedPhases.map(_.traversals).sum)
348348
runPhases(allPhases = fusedPhases)(using runCtx)
349+
ctx.reporter.finalizeReporting()
349350
if (!ctx.reporter.hasErrors)
350351
Rewrites.writeBack()
351352
suppressions.runFinished(hasErrors = ctx.reporter.hasErrors)

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,14 @@ abstract class Reporter extends interfaces.ReporterResult {
172172
end issueUnconfigured
173173

174174
def issueIfNotSuppressed(dia: Diagnostic)(using Context): Unit =
175-
def toErrorIfFatal(dia: Diagnostic) = dia match
176-
case w: Warning if ctx.settings.silentWarnings.value => dia
177-
case w: ConditionalWarning if w.isSummarizedConditional => dia
178-
case w: Warning if ctx.settings.XfatalWarnings.value => w.toError
179-
case _ => dia
180175

181176
def go() =
182177
import Action.*
183178
dia match
184179
case w: Warning => WConf.parsed.action(dia) match
185180
case Error => issueUnconfigured(w.toError)
186-
case Warning => issueUnconfigured(toErrorIfFatal(w))
187-
case Verbose => issueUnconfigured(toErrorIfFatal(w.setVerbose()))
181+
case Warning => issueUnconfigured(w)
182+
case Verbose => issueUnconfigured(w.setVerbose())
188183
case Info => issueUnconfigured(w.toInfo)
189184
case Silent =>
190185
case _ => issueUnconfigured(dia)
@@ -214,6 +209,10 @@ abstract class Reporter extends interfaces.ReporterResult {
214209
def incomplete(dia: Diagnostic)(using Context): Unit =
215210
incompleteHandler(dia, ctx)
216211

212+
def finalizeReporting()(using Context) =
213+
if (hasWarnings && ctx.settings.XfatalWarnings.value)
214+
report(new Error("No warnings can be incurred under -Werror.", NoSourcePosition))
215+
217216
/** Summary of warnings and errors */
218217
def summary: String = {
219218
val b = new mutable.ListBuffer[String]

0 commit comments

Comments
 (0)