scala - 如何正确使用 scalac -Xlint

标签 scala compiler-flags scalac scala-compiler

scalax -Xlint 帮助提供以下信息:

$ 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.
有没有办法启用所有检查? scalac -Xlint的语义是什么? ?它会启用所有吗?默认设置(哪个)?什么都不做?

Note: Scala 2.11.8 and sbt 0.13.9

If newer versions provide different behaviour/features let me know, as updating them is not a problem

最佳答案

-Xlint currently means -Xlint:_ ,但这需要 to be made explicit .

从历史上看,总是存在过于嘈杂或不可靠默认启用的警告,因此总是有警告被排除在 -Xlint 之外。 .

目前,有 one such lintable ,但它没有连接到命令行选项。

曾经有一个 -Ywarn-all这意味着 -Xlint加上那些其他警告。这个选项消失的原因并不明显。

一度,-Xlint:_意思是 -Ywarn-all , 与 -Xlint表示推荐的子集,但事实证明人们喜欢使用 -Xlint:-annoying,_ 禁用一两个 lint 规则,如果这可以启用任意许多其他嘈杂的 lint 规则,则更难做到。

通常,scalac -X显示默认值;但可能 scalac -Xlint:help将得到改进以显示其默认行为。对于诸如 -Yopt 之类的东西来说,这个默认值是很重要的。 .

$ scalac -help
Usage: scalac <options> <source files>
where possible standard options include:
  -X                              Print a synopsis of advanced options.


$ scalac -X
Usage: scalac <options> <source files>

-- Notes on option parsing --
Boolean settings are always false unless set.
Where multiple values are accepted, they should be comma-separated.
  example: -Xplugin:option1,option2
<phases> means one or a comma-separated list of:
  (partial) phase names, phase ids, phase id ranges, or the string "all".
  example: -Xprint:all prints all phases.
  example: -Xprint:expl,24-26 prints phases explicitouter, closelim, dce, jvm.
  example: -Xprint:-4 prints only the phases up to typer.

Possible advanced options include:
  -Xlint:<_,warning,-warning>    Enable or disable specific warnings: `_' for all, `-Xlint:help' to list

关于scala - 如何正确使用 scalac -Xlint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38028061/

相关文章:

gcc - -msse、-msse2、-mssse3、-msse4 rtc.. 的 cflgs sse 选项有什么区别?以及如何确定?

scala - 为什么 scalac 需要类路径的传递依赖

maven-3 - 编译scala时maven "rerun with -feature"

scala - 执行 Scalac -Xprint :typer? 时什么是 <stable> 和 <accessor>

string - 如何用scala中的其他文本替换字符串中的文本

json - 如何使用包含 "$"的列名进行查询?

scala - Spark:DataFrame如何在groupBy结果上使用Sum

arrays - 将字节数组转换为字符串

build - 是否可以将命令行变量传递给 bitbake 构建?

c - 我如何编译这个非常大但无聊的 C 源代码?