2016-01-05 74 views
1

我使用SBT建設項目,並在我的Build.scala發出警告名Scala的陰影2.11

scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-Xfatal-warnings") 

如何配置該項目上的名稱/可變陰影警告?我瀏覽過源herehere,但在許多選項中沒有看到我正在尋找的內容。對this old question的評論提到一個標誌-Ywarn-shadowing,似乎並不存在。

+0

也許有人知道一個scala守護者或疣卸妝。我手邊沒有看到它。還有其他用例:http://stackoverflow.com/questions/27587965/scala-making-sure-that-a-field-from-the-superclass-is-used https://issues.scala-lang.org /瀏覽/ SI-9100 https://issues.scala-lang.org/browse/SI-4762 –

+0

這包括情緒:http://stackoverflow.com/questions/12385293/how-can-i-get-scalac - 告訴我,如果我有,未使用的變量 –

回答

1

related question所示,您可以開始使用-X進行探索。然後,我嘗試-Xlint:help,這爲產生陰影的一些設置:

Information:scalac: 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. 

也許-Xlint:private-shadow是你想要的嗎?

+0

謝謝,這有助於,但我正在尋找變量的陰影,例如嵌套作用域中的'val',或者映射函數或方法參數的'val'。它看起來可能不可能,這對我來說有點杜鵑。 – jberryman

1

有許多斯卡拉短絨工具。 Scapegoat有一個選項VariableShadowing。我沒有看到更受歡迎的絨毛中的陰影選項,但是您可以自己實現一個。