Scala 2.12.2 发出大量无用的“警告:参数值...在方法中...从未使用过”警告。如何摆脱它们?
Posted
技术标签:
【中文标题】Scala 2.12.2 发出大量无用的“警告:参数值...在方法中...从未使用过”警告。如何摆脱它们?【英文标题】:Scala 2.12.2 emits a ton of useless "Warning: parameter value ... in method ... is never used" warnings. How to get rid of them? 【发布时间】:2017-10-13 08:35:20 【问题描述】:这是一个问题,因此我不必遍历整个 Internet 即可找到答案,因为目前尚未发布 scalac 选项。
当我有一个全局 "-Xlint"
时,如何从 Scala 2.12.2 开始禁用这些警告?
【问题讨论】:
谢谢,一些信息应该已经出现在发行说明中,但是我没有找到正确的使用说明。 github.com/scala/scala/releases 不是您的问题的答案,似乎已经提供了,但您确定这些不是合法的警告吗?并且没有办法从方法签名中删除未使用的参数? @halversonp 它们绝对是无用且无法修复的:例如trait def foo(implicit ec: ExecutionContext) = Future.successful(())
将发出警告,指出 ec
未使用,即使实现该 trait 的类确实使用了 ec
【参考方案1】:
$ 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.
所以
-Ywarn-unused:-params,_
但是:
$ 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.
所以
-Xlint:unused
或者更外科手术:
-Xlint:-unused,_ -Ywarn-unused:imports
有一个 PR 可以改善人体工程学,因此您可以任意组合设置/取消设置,但这是 2.12.2 的咒语。
【讨论】:
“有一个 PR 可以改善人体工程学”,链接?以上是关于Scala 2.12.2 发出大量无用的“警告:参数值...在方法中...从未使用过”警告。如何摆脱它们?的主要内容,如果未能解决你的问题,请参考以下文章
如何根据Scala中以前的未来响应发出多个HTTP GET请求?