1

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",

Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
  • It might help if you specified the compiler/linter options you use, but I would try `val _ = kryo.register(classOf[Foo])` – Gábor Bakos Dec 19 '17 at 20:30
  • your suggestion does not work as multiple calls to the function `kryo.register(classOf[Foo]) kryo.register(classOf[Bar])` will fail then. – Georg Heiler Dec 19 '17 at 20:34

1 Answers1

3

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
g.krastev
  • 1,193
  • 7
  • 19