Is there an equivalent to SuppressWarnings in Scala?
Scala 2.13.2 provides @nowarn
annotation developed on the basis of ghik's silencer
, for example
import scala.annotation.nowarn
def t = { 0: @nowarn; 1 }
raises no warnings, whilst
def t = { 0; 1 }
gives
warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses
def t = { 0; 1 }
^
EDIT: You should use @nowarn
There is a simple compiler plugin for this: silencer (a bit shameless plug)
No, and an enhancement request [1] for such a feature was closed as wontfix
.
I agree it would be useful. I expect that the Scala core team aren't against the idea, but they have finite resources and many higher priorities.
update: this feature was eventually implemented in scala 2.13.2 release on 2020-04-22, see this answer
[1] https://issues.scala-lang.org/browse/SI-1781