Reporter counts warnings when `-nowarn` is enabled
Because -nowarn is "just" setting -Xmaxwarns 0, warnings are not displayed but still counted in the reporter.
Maybe not a bug? Thoughts welcome. It's an easy fix in FilteringReporter.
Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 17.0.1).
Type in expressions for evaluation. Or try :help.
scala> import scala.tools.nsc._
| import scala.tools.nsc.interpreter._
| import scala.tools.nsc.interpreter.shell._
| val s = new Settings()
| s.nowarn.value = true
| val r = new ReplReporterImpl(s) { override def reset(): Unit = () } // interpreter calls `reset` after each line
| val i = new IMain(s, r)
| i.interpret("val x: Unit = 1")
| r.warningCount
val x: Unit = ()
import scala.tools.nsc._
import scala.tools.nsc.interpreter._
import scala.tools.nsc.interpreter.shell._
val s: scala.tools.nsc.Settings =
Settings {
-encoding = UTF-8
-nowarn = true
-Xmaxwarns = 0
}
// mutated s.nowarn.value
val r: scala.tools.nsc.interpreter.shell.ReplReporterImpl = $anon$1@594c66c3
val i: scala.tools.nsc.interpreter.IMain = scala.tools.nsc.interpreter.IMain@64e657b0
val res0: Int = 1
It doesn't trigger -Werror. I wonder what happens if I -Wconfig as e. I expect that will still error under -nowarn.
➜ snips scalac -d /tmp -Xlint -Werror t12664.scala
t12664.scala:3: warning: side-effecting nullary methods are discouraged: suggest defining as `def f()` instead
def f: Unit = 42
^
t12664.scala:3: warning: a pure expression does nothing in statement position
def f: Unit = 42
^
error: No warnings can be incurred under -Werror.
2 warnings
1 error
➜ snips scalac -nowarn -d /tmp -Xlint -Werror t12664.scala
➜ snips scalac -nowarn -d /tmp -Xlint -Werror -Wvalue-discard t12664.scala
➜ snips scalac -d /tmp -Xlint -Werror -Wvalue-discard t12664.scala
t12664.scala:3: warning: discarded non-Unit value of type Int(42)
def f: Unit = 42
^
t12664.scala:3: warning: side-effecting nullary methods are discouraged: suggest defining as `def f()` instead
def f: Unit = 42
^
t12664.scala:3: warning: a pure expression does nothing in statement position
def f: Unit = 42
^
error: No warnings can be incurred under -Werror.
3 warnings
1 error
➜ snips
and
➜ snips scalac -d /tmp -Xlint -Wconf:msg=discarded:e -Wvalue-discard t12664.scala
t12664.scala:3: error: discarded non-Unit value of type Int(42)
def f: Unit = 42
^
1 error
➜ snips scalac -nowarn -d /tmp -Xlint -Wconf:msg=discarded:e -Wvalue-discard t12664.scala
t12664.scala:3: error: discarded non-Unit value of type Int(42)
def f: Unit = 42
^
1 error
It would be annoying if it reported:
warning: warnings reported, re-run with -nowarn:false for more information
@lrytz You self-assigned, here. Are you planning to return to it?
Looking at my second example, I would expect -nowarn be a -Wconf "alias" that means "silence any other warning", so that particular warnings could be boosted to error, as currently.
-Xmaxwarns just means "output management" to me, so I would not expect it to silence -Werror.
I can see how before -Wconf, it made sense to equate -nowarn and -Xmaxwarns 0.
I hope lrytz remembers the easy fix.
I see in a discussion from 2020 that I've always been confused by the reporting regime. I'll try to summarize my comment in the test to the PR.
The "per-run" reporting infra and the "sink" or "backend" reporter are separate entities and need not cooperate in reporting.
My tweak to -nowarn is -Wconf:any:s. In addition, the default cat=deprecation:ws must be updated to w if -deprecation and s otherwise. That reduces diagnostics, but arbitrary -Wconf is allowed.
The previous tweak to the sink Reporter was to refrain from summarizing under -nowarn. The maxwarns trick filters warnings in FilteringReporter.
To the main question, then, the warning count represents the warnings I asked for.
cat=lint-missing-interpolator:ws
is just to give me some idea of how many are missing. Maybe a few crept in again during a commit. So I -nowarn to keep my build going under -Werror.
There is a test using reporter.warning, which circumvents per-run; so -nowarn is a distinct signal to both per-run and sink.