Skip to content

Commit

Permalink
Check if a fatal warning issued in typer is silenced, before converti…
Browse files Browse the repository at this point in the history
…ng it into an error

closes lampepfl#17741
closes lampepfl#17735
  • Loading branch information
KacperFKorban committed Jun 28, 2023
1 parent 0749271 commit bb1fd4a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
21 changes: 11 additions & 10 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,10 @@ abstract class Reporter extends interfaces.ReporterResult {
val key = w.enablingOption.name
addUnreported(key, 1)
case _ =>
// conditional warnings that are not enabled are not fatal
val d = dia match
case w: Warning if ctx.settings.XfatalWarnings.value => w.toError
case _ => dia
if !isHidden(d) then // avoid isHidden test for summarized warnings so that message is not forced
markReported(d)
withMode(Mode.Printing)(doReport(d))
d match {
if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced
markReported(dia)
withMode(Mode.Printing)(doReport(dia))
dia match {
case _: Warning => _warningCount += 1
case e: Error =>
errors = e :: errors
Expand All @@ -171,14 +167,19 @@ abstract class Reporter extends interfaces.ReporterResult {
def issueIfNotSuppressed(dia: Diagnostic)(using Context): Unit =
def go() =
import Action._
dia match
val d = dia match
case w: Warning if ctx.settings.silentWarnings.value => dia
case w: ConditionalWarning if w.isSummarizedConditional => dia
case w: Warning if !ctx.settings.silentWarnings.value && ctx.settings.XfatalWarnings.value => w.toError
case _ => dia
d match
case w: Warning => WConf.parsed.action(w) match
case Error => issueUnconfigured(w.toError)
case Warning => issueUnconfigured(w)
case Verbose => issueUnconfigured(w.setVerbose())
case Info => issueUnconfigured(w.toInfo)
case Silent =>
case _ => issueUnconfigured(dia)
case _ => issueUnconfigured(d)

// `ctx.run` can be null in test, also in the repl when parsing the first line. The parser runs early, the Run is
// only created in ReplDriver.compile when a line is submitted. This means that `@nowarn` doesnt work on parser
Expand Down
32 changes: 16 additions & 16 deletions tests/neg/refutable-pattern-binding-messages.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-- Error: tests/neg/refutable-pattern-binding-messages.scala:5:14 ------------------------------------------------------
5 | val Positive(p) = 5 // error: refutable extractor
| ^^^^^^^^^^^^^^^
| pattern binding uses refutable extractor `Test.Positive`
|
| If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
| which may result in a MatchError at runtime.
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
-- Error: tests/neg/refutable-pattern-binding-messages.scala:6:14 ------------------------------------------------------
6 | for Positive(i) <- List(1, 2, 3) do () // error: refutable extractor
| ^^^^^^^^^^^
Expand All @@ -6,6 +14,14 @@
| If this usage is intentional, this can be communicated by adding the `case` keyword before the full pattern,
| which will result in a filtering for expression (using `withFilter`).
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
-- Error: tests/neg/refutable-pattern-binding-messages.scala:10:20 -----------------------------------------------------
10 | val i :: is = List(1, 2, 3) // error: pattern type more specialized
| ^^^^^^^^^^^^^
| pattern's type ::[Int] is more specialized than the right hand side expression's type List[Int]
|
| If the narrowing is intentional, this can be communicated by adding `: @unchecked` after the expression,
| which may result in a MatchError at runtime.
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
-- Error: tests/neg/refutable-pattern-binding-messages.scala:11:11 -----------------------------------------------------
11 | for ((x: String) <- xs) do () // error: pattern type more specialized
| ^^^^^^
Expand All @@ -22,22 +38,6 @@
| If the narrowing is intentional, this can be communicated by adding the `case` keyword before the full pattern,
| which will result in a filtering for expression (using `withFilter`).
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
-- Error: tests/neg/refutable-pattern-binding-messages.scala:5:14 ------------------------------------------------------
5 | val Positive(p) = 5 // error: refutable extractor
| ^^^^^^^^^^^^^^^
| pattern binding uses refutable extractor `Test.Positive`
|
| If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
| which may result in a MatchError at runtime.
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
-- Error: tests/neg/refutable-pattern-binding-messages.scala:10:20 -----------------------------------------------------
10 | val i :: is = List(1, 2, 3) // error: pattern type more specialized
| ^^^^^^^^^^^^^
| pattern's type ::[Int] is more specialized than the right hand side expression's type List[Int]
|
| If the narrowing is intentional, this can be communicated by adding `: @unchecked` after the expression,
| which may result in a MatchError at runtime.
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
-- Error: tests/neg/refutable-pattern-binding-messages.scala:16:10 -----------------------------------------------------
16 | val 1 = 2 // error: pattern type does not match
| ^
Expand Down
16 changes: 8 additions & 8 deletions tests/neg/warn-value-discard.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
-- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:15:35 ----------------------------------------------
15 | firstThing().map(_ => secondThing()) // error
| ^^^^^^^^^^^^^
| discarded non-Unit value of type Either[Failed, Unit]
-- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:18:35 ----------------------------------------------
18 | firstThing().map(_ => secondThing()) // error
| ^^^^^^^^^^^^^
| discarded non-Unit value of type Either[Failed, Unit]
-- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:27:36 ----------------------------------------------
27 | mutable.Set.empty[String].remove("") // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -18,3 +10,11 @@
59 | mutable.Set.empty[String] += "" // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| discarded non-Unit value of type scala.collection.mutable.Set[String]
-- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:15:35 ----------------------------------------------
15 | firstThing().map(_ => secondThing()) // error
| ^^^^^^^^^^^^^
| discarded non-Unit value of type Either[Failed, Unit]
-- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:18:35 ----------------------------------------------
18 | firstThing().map(_ => secondThing()) // error
| ^^^^^^^^^^^^^
| discarded non-Unit value of type Either[Failed, Unit]
6 changes: 6 additions & 0 deletions tests/pos-special/fatal-warnings/i17741.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
case class F(i: Int)

object Main {
def example() =
List(1, 2, 3).map(F): @annotation.nowarn
}

0 comments on commit bb1fd4a

Please sign in to comment.