summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc')
-rw-r--r--src/compiler/scala/tools/nsc/settings/MutableSettings.scala21
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala16
-rw-r--r--src/compiler/scala/tools/nsc/settings/Warnings.scala22
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala7
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Analyzer.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala2
7 files changed, 44 insertions, 32 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
index 0536be92cf..3590254128 100644
--- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
@@ -438,6 +438,17 @@ class MutableSettings(val errorFn: String => Unit)
override def tryToSetFromPropertyValue(s : String) { // used from ide
value = s.equalsIgnoreCase("true")
}
+ override def tryToSetColon(args: List[String]) = args match {
+ case Nil => tryToSet(Nil)
+ case List(x) =>
+ if (x.equalsIgnoreCase("true")) {
+ value = true
+ Some(Nil)
+ } else if (x.equalsIgnoreCase("false")) {
+ value = false
+ Some(Nil)
+ } else errorAndValue("'" + x + "' is not a valid choice for '" + name + "'", None)
+ }
}
/** A special setting for accumulating arguments like -Dfoo=bar. */
@@ -668,4 +679,14 @@ class MutableSettings(val errorFn: String => Unit)
else name + "[:phases]"
)
}
+
+ /** Internal use - syntax enhancements. */
+ protected class EnableSettings[T <: BooleanSetting](val s: T) {
+ def enablingIfNotSetByUser(toEnable: List[BooleanSetting]): s.type = s withPostSetHook (_ => toEnable foreach (sett => if (!sett.isSetByUser) sett.value = s.value))
+ def enabling(toEnable: List[BooleanSetting]): s.type = s withPostSetHook (_ => toEnable foreach (_.value = s.value))
+ def disabling(toDisable: List[BooleanSetting]): s.type = s withPostSetHook (_ => toDisable foreach (_.value = !s.value))
+ def andThen(f: s.T => Unit): s.type = s withPostSetHook (setting => f(setting.value))
+ }
+ import scala.language.implicitConversions
+ protected implicit def installEnableSettings[T <: BooleanSetting](s: T): EnableSettings[T] = new EnableSettings(s)
}
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index a385a31165..a643a08614 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -20,7 +20,7 @@ trait ScalaSettings extends AbsScalaSettings
self: MutableSettings =>
/** Set of settings */
- protected lazy val allSettings = mutable.HashSet[Setting]()
+ protected[scala] lazy val allSettings = mutable.HashSet[Setting]()
/** Against my better judgment, giving in to martin here and allowing
* CLASSPATH to be used automatically. So for the user-specified part
@@ -47,14 +47,6 @@ trait ScalaSettings extends AbsScalaSettings
/** Is an info setting set? */
def isInfo = infoSettings exists (_.isSetByUser)
- /** Internal use - syntax enhancements. */
- private class EnableSettings[T <: BooleanSetting](val s: T) {
- def enabling(toEnable: List[BooleanSetting]): s.type = s withPostSetHook (_ => toEnable foreach (_.value = s.value))
- def disabling(toDisable: List[BooleanSetting]): s.type = s withPostSetHook (_ => toDisable foreach (_.value = !s.value))
- def andThen(f: s.T => Unit): s.type = s withPostSetHook (setting => f(setting.value))
- }
- private implicit def installEnableSettings[T <: BooleanSetting](s: T) = new EnableSettings(s)
-
/** Disable a setting */
def disable(s: Setting) = allSettings -= s
@@ -216,10 +208,10 @@ trait ScalaSettings extends AbsScalaSettings
/** Groups of Settings.
*/
- val future = BooleanSetting("-Xfuture", "Turn on future language features.") enabling futureSettings
- val optimise = BooleanSetting("-optimise", "Generates faster bytecode by applying optimisations to the program") withAbbreviation "-optimize" enabling optimiseSettings
+ val future = BooleanSetting("-Xfuture", "Turn on future language features.") enablingIfNotSetByUser futureSettings
+ val optimise = BooleanSetting("-optimise", "Generates faster bytecode by applying optimisations to the program") withAbbreviation "-optimize" enablingIfNotSetByUser optimiseSettings
val nooptimise = BooleanSetting("-Ynooptimise", "Clears all the flags set by -optimise. Useful for testing optimizations in isolation.") withAbbreviation "-Ynooptimize" disabling optimise::optimiseSettings
- val Xexperimental = BooleanSetting("-Xexperimental", "Enable experimental extensions.") enabling experimentalSettings
+ val Xexperimental = BooleanSetting("-Xexperimental", "Enable experimental extensions.") enablingIfNotSetByUser experimentalSettings
/**
* Settings motivated by GenBCode
diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala
index 791d44153c..1509ad13b8 100644
--- a/src/compiler/scala/tools/nsc/settings/Warnings.scala
+++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala
@@ -7,6 +7,8 @@ package scala.tools
package nsc
package settings
+import language.existentials
+
/** Settings influencing the printing of warnings.
*/
trait Warnings {
@@ -30,21 +32,10 @@ trait Warnings {
warnNullaryUnit,
warnAdaptedArgs,
warnInferAny
+ // warnUnused SI-7712, SI-7707 warnUnused not quite ready for prime-time
+ // warnUnusedImport currently considered too noisy for general use
)
- // Warning groups.
- val lint = (
- BooleanSetting("-Xlint", "Enable recommended additional warnings.")
- withPostSetHook (_ => lintWarnings foreach (_.value = true))
- )
-
- /*val warnEverything = */ (
- BooleanSetting("-Ywarn-all", "Enable all -Y warnings.")
- withPostSetHook { _ =>
- lint.value = true
- allWarnings foreach (_.value = true)
- }
- )
private lazy val warnSelectNullable = BooleanSetting("-Xcheck-null", "This option is obsolete and does nothing.")
// Individual warnings.
@@ -56,6 +47,11 @@ trait Warnings {
val warnInaccessible = BooleanSetting ("-Ywarn-inaccessible", "Warn about inaccessible types in method signatures.")
val warnNullaryOverride = BooleanSetting ("-Ywarn-nullary-override", "Warn when non-nullary overrides nullary, e.g. `def foo()` over `def foo`.")
val warnInferAny = BooleanSetting ("-Ywarn-infer-any", "Warn when a type argument is inferred to be `Any`.")
+ val warnUnused = BooleanSetting ("-Ywarn-unused", "Warn when local and private vals, vars, defs, and types are are unused")
+ val warnUnusedImport = BooleanSetting ("-Ywarn-unused-import", "Warn when imports are unused")
+
+ // Warning groups.
+ val lint = BooleanSetting("-Xlint", "Enable recommended additional warnings.") enablingIfNotSetByUser lintWarnings
// Backward compatibility.
@deprecated("Use fatalWarnings", "2.11.0") def Xwarnfatal = fatalWarnings // used by sbt
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index eba2e1399d..bd2f6f0018 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -238,8 +238,11 @@ abstract class Erasure extends AddInterfaces
if (!(AnyRefTpe <:< bounds.hi)) "+" + boxedSig(bounds.hi)
else if (!(bounds.lo <:< NullTpe)) "-" + boxedSig(bounds.lo)
else "*"
- } else {
- boxedSig(tp)
+ } else tp match {
+ case PolyType(_, res) =>
+ "*" // SI-7932
+ case _ =>
+ boxedSig(tp)
}
def classSig = {
val preRebound = pre.baseType(sym.owner) // #2585
diff --git a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
index 5c02516c47..323fe1c171 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
@@ -102,7 +102,9 @@ trait Analyzer extends AnyRef
unit.body = typer.typed(unit.body)
if (global.settings.Yrangepos && !global.reporter.hasErrors) global.validatePositions(unit.body)
for (workItem <- unit.toCheck) workItem()
- if (settings.lint)
+ if (settings.warnUnusedImport)
+ warnUnusedImports(unit)
+ if (settings.warnUnused)
typer checkUnused unit
}
finally {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 6e9e16ffc9..98ee4ad94d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -1207,7 +1207,7 @@ trait Contexts { self: Analyzer =>
trait ImportContext extends Context {
private val impInfo: ImportInfo = {
val info = new ImportInfo(tree.asInstanceOf[Import], outerDepth)
- if (settings.lint && !isRootImport) // excludes java.lang/scala/Predef imports
+ if (settings.warnUnusedImport && !isRootImport) // excludes java.lang/scala/Predef imports
allImportInfos(unit) ::= info
info
}
@@ -1316,7 +1316,7 @@ trait Contexts { self: Analyzer =>
if (result == NoSymbol)
selectors = selectors.tail
}
- if (settings.lint && selectors.nonEmpty && result != NoSymbol && pos != NoPosition)
+ if (settings.warnUnusedImport && selectors.nonEmpty && result != NoSymbol && pos != NoPosition)
recordUsage(current, result)
// Harden against the fallout from bugs like SI-6745
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
index ca960d7b11..60346e7be1 100644
--- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
@@ -518,8 +518,6 @@ trait TypeDiagnostics {
}
def apply(unit: CompilationUnit) = {
- warnUnusedImports(unit)
-
val p = new UnusedPrivates
p traverse unit.body
val unused = p.unusedTerms