Skip to content

Commit 3185453

Browse files
committed
Issue unused nowarn warning only if the compiler run has no errors
1 parent 927d22d commit 3185453

File tree

8 files changed

+116
-117
lines changed

8 files changed

+116
-117
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,14 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
270270
runCtx.setProfiler(Profiler())
271271
unfusedPhases.foreach(_.initContext(runCtx))
272272
runPhases(using runCtx)
273-
if (!ctx.reporter.hasErrors) Rewrites.writeBack()
273+
if (!ctx.reporter.hasErrors)
274+
Rewrites.writeBack()
275+
// later phases don't run when there are errors, which would lead to stale `unused @nowarn` warnings
276+
suppressions.warnUnusedSuppressions()
274277
while (finalizeActions.nonEmpty) {
275278
val action = finalizeActions.remove(0)
276279
action()
277280
}
278-
suppressions.warnUnusedSuppressions()
279281
compiling = false
280282
}
281283

Diff for: compiler/test/dotty/tools/dotc/CompilationTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class CompilationTests {
128128
compileFilesInDir("tests/neg-no-kind-polymorphism", defaultOptions and "-Yno-kind-polymorphism"),
129129
compileFilesInDir("tests/neg-custom-args/deprecation", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
130130
compileFilesInDir("tests/neg-custom-args/fatal-warnings", defaultOptions.and("-Xfatal-warnings")),
131-
compileFilesInDir("tests/neg-custom-args/nowarn", defaultOptions.and("-deprecation", "-Werror", "-Wunused:nowarn")),
131+
compileFilesInDir("tests/neg-custom-args/nowarn", defaultOptions.and("-deprecation", "-Wunused:nowarn", "-Wconf:msg=@nowarn annotation does not suppress any warnings:e")),
132132
compileFilesInDir("tests/neg-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions")),
133133
compileFilesInDir("tests/neg-custom-args/allow-double-bindings", allowDoubleBindings),
134134
compileFilesInDir("tests/neg-custom-args/allow-deep-subtypes", allowDeepSubtypes),

Diff for: tests/neg-custom-args/nowarn/nowarn-parser-typer.check

-39
This file was deleted.

Diff for: tests/neg-custom-args/nowarn/nowarn-parser-typer.scala

-26
This file was deleted.

Diff for: tests/neg-custom-args/nowarn/nowarn-refchecks.check

-24
This file was deleted.

Diff for: tests/neg-custom-args/nowarn/nowarn-refchecks.scala

-25
This file was deleted.

Diff for: tests/neg-custom-args/nowarn/nowarn.check

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:9:10 -----------------------------------------------
2+
9 |def t1a = try 1 // warning (parser)
3+
| ^^^^^
4+
| A try without catch or finally is equivalent to putting
5+
| its body in a block; no exceptions are handled.
6+
7+
longer explanation available when compiling with `-explain`
8+
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:21:26 ----------------------------------------------
9+
21 |@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
10+
| ^^^^^
11+
| A try without catch or finally is equivalent to putting
12+
| its body in a block; no exceptions are handled.
13+
14+
longer explanation available when compiling with `-explain`
15+
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:23:28 ----------------------------------------------
16+
23 |@nowarn("verbose") def t5 = try 1 // warning with details
17+
| ^^^^^
18+
| A try without catch or finally is equivalent to putting
19+
| its body in a block; no exceptions are handled.
20+
Matching filters for @nowarn or -Wconf:
21+
- id=E0
22+
- name=EmptyCatchOrFinallyBlock
23+
24+
longer explanation available when compiling with `-explain`
25+
-- [E129] Potential Issue Warning: tests/neg-custom-args/nowarn/nowarn.scala:13:11 -------------------------------------
26+
13 |def t2 = { 1; 2 } // warning (the invalid nowarn doesn't silence anything)
27+
| ^
28+
| A pure expression does nothing in statement position; you may be omitting necessary parentheses
29+
30+
longer explanation available when compiling with `-explain`
31+
-- Warning: tests/neg-custom-args/nowarn/nowarn.scala:12:8 -------------------------------------------------------------
32+
12 |@nowarn("wat?") // warning (typer, invalid filter)
33+
| ^^^^^^
34+
| Invalid message filter
35+
| unknown filter: wat?
36+
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:27:10 ------------------------------------------------
37+
27 |def t6a = f // warning (refchecks, deprecation)
38+
| ^
39+
| method f is deprecated
40+
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:30:30 ------------------------------------------------
41+
30 |@nowarn("msg=fish") def t6d = f // error (unused nowarn), warning (deprecation)
42+
| ^
43+
| method f is deprecated
44+
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:37:10 ------------------------------------------------
45+
37 |def t7c = f: // warning (deprecation)
46+
| ^
47+
| method f is deprecated
48+
-- Unchecked Warning: tests/neg-custom-args/nowarn/nowarn.scala:43:7 ---------------------------------------------------
49+
43 | case _: List[Int] => 0 // warning (patmat, unchecked)
50+
| ^
51+
| the type test for List[Int] cannot be checked at runtime
52+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:21:1 ---------------------------------------------------------------
53+
21 |@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
54+
|^^^^^^^^^^^^^^^
55+
|@nowarn annotation does not suppress any warnings
56+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:30:1 ---------------------------------------------------------------
57+
30 |@nowarn("msg=fish") def t6d = f // error (unused nowarn), warning (deprecation)
58+
|^^^^^^^^^^^^^^^^^^^
59+
|@nowarn annotation does not suppress any warnings
60+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:38:3 ---------------------------------------------------------------
61+
38 | @nowarn("msg=fish") // error (unused nowarn)
62+
| ^^^^^^^^^^^^^^^^^^^
63+
| @nowarn annotation does not suppress any warnings

Diff for: tests/neg-custom-args/nowarn/nowarn.scala

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import annotation.nowarn
2+
3+
// This test doesn't run with `-Werror`, because once there's an error, later phases are skipped and we would not see
4+
// their warnings.
5+
// Instead, this test runs with `-Wunused:nowarn -Wconf:msg=@nowarn annotation does not suppress any warnings:e`.
6+
// Only "unused nowarn" warnings are reported as errors. Since these warnings are reported at the very end, all other
7+
// phases of the compiler run normally.
8+
9+
def t1a = try 1 // warning (parser)
10+
@nowarn("msg=try without catch") def t1b = try 1
11+
12+
@nowarn("wat?") // warning (typer, invalid filter)
13+
def t2 = { 1; 2 } // warning (the invalid nowarn doesn't silence anything)
14+
15+
@nowarn("id=E129") def t3a = { 1; 2 }
16+
@nowarn("name=PureExpressionInStatementPosition") def t3b = { 1; 2 }
17+
18+
@nowarn("id=E000") def t4a = try 1
19+
@nowarn("id=E0") def t4b = try 1
20+
@nowarn("id=0") def t4c = try 1
21+
@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
22+
23+
@nowarn("verbose") def t5 = try 1 // warning with details
24+
25+
@deprecated def f = 0
26+
27+
def t6a = f // warning (refchecks, deprecation)
28+
@nowarn("cat=deprecation") def t6b = f
29+
@nowarn("msg=deprecated") def t6c = f
30+
@nowarn("msg=fish") def t6d = f // error (unused nowarn), warning (deprecation)
31+
@nowarn("") def t6e = f
32+
@nowarn def t6f = f
33+
34+
def t7a = f: @nowarn("cat=deprecation")
35+
def t7b = f:
36+
@nowarn("msg=deprecated")
37+
def t7c = f: // warning (deprecation)
38+
@nowarn("msg=fish") // error (unused nowarn)
39+
def t7d = f: @nowarn("")
40+
def t7e = f: @nowarn
41+
42+
def t8a(x: Any) = x match
43+
case _: List[Int] => 0 // warning (patmat, unchecked)
44+
case _ => 1
45+
46+
@nowarn("cat=unchecked") def t8(x: Any) = x match
47+
case _: List[Int] => 0
48+
case _ => 1

0 commit comments

Comments
 (0)