Scala 2.12.2 emits a ton of useless "Warning: parameter value ... in method ... is never used" warnings. How to get rid of them?
Asked Answered
M

1

11

This is a question so I don't have to traverse the entire Internet to find the answer, as scalac options are currently not published.

How do I disable these warnings starting in Scala 2.12.2, when I have a global "-Xlint"?

Maeve answered 14/5, 2017 at 13:42 Comment(3)
Thanks, some info should have surfaced in release notes, but I haven't found the right place for usage notes. github.com/scala/scala/releasesEllon
Not an answer to your question, which seems to have been provided already, but you're sure these aren't legitimate warnings? And no way to remove the unused parameters from the method signatures?Disaffirm
@halversonp they can definitely be useless and unfixable: e.g. trait { def foo(implicit ec: ExecutionContext) = Future.successful(()) will emit a warning that ec is unused, even if classes implementing the trait do use the ecNose
E
21
$ scalac -Ywarn-unused:help
Enable or disable specific `unused' warnings
  imports    Warn if an import selector is not referenced.
  patvars    Warn if a variable bound in a pattern is unused.
  privates   Warn if a private member is unused.
  locals     Warn if a local definition is unused.
  params     Warn if a value parameter is unused.
  implicits  Warn if an implicit parameter is unused.
Default: All choices are enabled by default.

So

-Ywarn-unused:-params,_

But:

$ scalac -Xlint:help
Enable or disable specific warnings
  adapted-args               Warn if an argument list is modified to match the receiver.
  nullary-unit               Warn when nullary methods return Unit.
  inaccessible               Warn about inaccessible types in method signatures.
  nullary-override           Warn when non-nullary `def f()' overrides nullary `def f'.
  infer-any                  Warn when a type argument is inferred to be `Any`.
  missing-interpolator       A string literal appears to be missing an interpolator id.
  doc-detached               A Scaladoc comment appears to be detached from its element.
  private-shadow             A private field (or class parameter) shadows a superclass field.
  type-parameter-shadow      A local type parameter shadows a type already in scope.
  poly-implicit-overload     Parameterized overloaded implicit methods are not visible as view bounds.
  option-implicit            Option.apply used implicit view.
  delayedinit-select         Selecting member of DelayedInit.
  by-name-right-associative  By-name parameter of right associative operator.
  package-object-classes     Class or object defined in package object.
  unsound-match              Pattern match may not be typesafe.
  stars-align                Pattern sequence wildcard must align with sequence component.
  constant                   Evaluation of a constant arithmetic expression results in an error.
  unused                     Enable -Ywarn-unused:imports,privates,locals,implicits.

So

-Xlint:unused

Or also more surgically:

-Xlint:-unused,_ -Ywarn-unused:imports

There's a PR to improve ergonomics, so you can set/unset in arbitrary combinations, but this is the incantation for 2.12.2.

Ellon answered 14/5, 2017 at 15:29 Comment(3)
"There's a PR to improve ergonomics", link?Throstle
What does the trailing comma and underscore mean after disabling unused? Where can I read about this syntax?Faqir
@Faqir scalac -X at the end of help says "Multi-valued settings are comma-separated" and "Use _ to enable all". There is a ticket to improve the online doc page docs.scala-lang.org/overviews/compiler-options/index.htmlEllon

© 2022 - 2024 — McMap. All rights reserved.