Skip to content

Commit b26acda

Browse files
committed
show parser warnings when there are parser errors
1 parent 622ed5c commit b26acda

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

Diff for: compiler/src/dotty/tools/dotc/Run.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
140140
mySuspendedMessages.remove(source).foreach(_.foreach(ctx.reporter.issueIfNotSuppressed))
141141
}
142142

143-
def warnUnusedSuppressions(): Unit =
144-
// if we stop before typer completes (errors in parser, Ystop), report all suspended messages
143+
def runFinished(hasErrors: Boolean): Unit =
144+
// report suspended messages (in case the run finished before typer)
145145
mySuspendedMessages.keysIterator.toList.foreach(reportSuspendedMessages)
146-
if ctx.settings.WunusedHas.nowarn then
146+
// report unused nowarns only if all all phases are done
147+
if !hasErrors && ctx.settings.WunusedHas.nowarn then
147148
for {
148149
source <- mySuppressions.keysIterator.toList
149150
sups <- mySuppressions.remove(source)
@@ -279,8 +280,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
279280
runPhases(using runCtx)
280281
if (!ctx.reporter.hasErrors)
281282
Rewrites.writeBack()
282-
// later phases don't run when there are errors, which would lead to stale `unused @nowarn` warnings
283-
suppressions.warnUnusedSuppressions()
283+
suppressions.runFinished(hasErrors = ctx.reporter.hasErrors)
284284
while (finalizeActions.nonEmpty) {
285285
val action = finalizeActions.remove(0)
286286
action()
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- [E040] Syntax Error: tests/neg-custom-args/nowarn/nowarn-parser-error.scala:3:6 -------------------------------------
2+
3 | def def // error
3+
| ^^^
4+
| an identifier expected, but 'def' found
5+
6+
longer explanation available when compiling with `-explain`
7+
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn-parser-error.scala:2:10 ----------------------------------
8+
2 | def a = try 1 // warn
9+
| ^^^^^
10+
| A try without catch or finally is equivalent to putting
11+
| its body in a block; no exceptions are handled.
12+
13+
longer explanation available when compiling with `-explain`
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class C {
2+
def a = try 1 // warn
3+
def def // error
4+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- [E006] Not Found Error: tests/neg-custom-args/nowarn/nowarn-typer-error.scala:4:11 ----------------------------------
2+
4 | def t1 = / // error
3+
| ^
4+
| Not found: /
5+
6+
longer explanation available when compiling with `-explain`
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import annotation.nowarn
2+
object T {
3+
@deprecated def f = 1
4+
def t1 = / // error
5+
@nowarn // unused-nowarn is not issued if earlier phase has an error.
6+
def t2 = f // no warning, refchecks doesn't run if typer has an error
7+
}

0 commit comments

Comments
 (0)