Georg Heiler
Georg Heiler

Reputation: 17676

scala actually suppress compiler warnings

how can I actually suppress the compiler warning for:

discarded non-Unit value
[warn]     kryo.register(classOf[Foo])

The suggestion of Suppress "discarded non-Unit value" warning does not apply since the problem takes place outside of my own code.

edit

compiler options are:

"-target:jvm-1.8",
  "-encoding",
  "UTF-8",
  "-feature",
  "-unchecked",
  "-deprecation",
  "-Xfuture",
  "-Xlint:missing-interpolator",
  "-Yno-adapted-args",
  "-Ywarn-dead-code",
  "-Ywarn-numeric-widen",
  "-Ywarn-value-discard",
  "-Ywarn-dead-code",
  "-Ywarn-unused"

which will warn "-Ywarn-value-discard",

Upvotes: 1

Views: 1542

Answers (1)

g.krastev
g.krastev

Reputation: 1213

You should just return Unit explicitly from the block where you call kryo.register. If there is no block, wrap it in one:

{
  kryo.register(classOf[Foo])
  kryo.register(classOf[Bar])
  () // I know what I'm doing
}

About warning suppression in general

Unfortunately Scala has no built-in suppression system. People have been asking for this but it's not trivial to achieve. For now there are two options:

  1. Disable the warning entirely
  2. Use a compiler plugin: silencer

Upvotes: 3

Related Questions