summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-09-10 15:17:49 -0700
committerSom Snytt <som.snytt@gmail.com>2016-09-10 15:17:49 -0700
commit94518ce0be2ffdb06d1d3f81279fdc05fa568c0b (patch)
tree4307f49d1d098ed34460f8e648837cecea19f2c2
parent05016d9035ab9b1c866bd9f12fdd0491f1ea0cbb (diff)
downloadscala-94518ce0be2ffdb06d1d3f81279fdc05fa568c0b.tar.gz
scala-94518ce0be2ffdb06d1d3f81279fdc05fa568c0b.tar.bz2
scala-94518ce0be2ffdb06d1d3f81279fdc05fa568c0b.zip
No warn when discarding r.f(): r.type
The paradigm is `def add(x: X): Unit = listBuffer += x`. The value that is discarded is not new information. Also cleans up the recent tweaks to help messaging. Adds newlines in case they ask for multiple helps.
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala10
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala7
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala9
-rw-r--r--src/repl/scala/tools/nsc/MainGenericRunner.scala6
-rw-r--r--test/files/pos/t9020.scala6
5 files changed, 17 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index 3879d7b425..24da6ba487 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -103,15 +103,7 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
val components = global.phaseNames // global.phaseDescriptors // one initializes
s"Phase graph of ${components.size} components output to ${genPhaseGraph.value}*.dot."
}
- // would be nicer if we could ask all the options for their helpful messages
- else {
- val sb = new StringBuilder
- allSettings foreach {
- case s if s.isHelping => sb append s.help
- case _ =>
- }
- sb.toString
- }
+ else allSettings.filter(_.isHelping).map(_.help).mkString("\n\n")
}
/**
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index e10fa3a114..d81d688267 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -38,11 +38,8 @@ trait ScalaSettings extends AbsScalaSettings
/** If any of these settings is enabled, the compiler should print a message and exit. */
def infoSettings = List[Setting](version, help, Xhelp, Yhelp, showPlugins, showPhases, genPhaseGraph)
- /** Any -option:help? */
- private def multihelp = allSettings exists { case s => s.isHelping case _ => false }
-
- /** Is an info setting set? */
- def isInfo = (infoSettings exists (_.isSetByUser)) || multihelp
+ /** Is an info setting set? Any -option:help? */
+ def isInfo = infoSettings.exists(_.isSetByUser) || allSettings.exists(_.isHelping)
/** Disable a setting */
def disable(s: Setting) = allSettings -= s
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index d8183ea8df..7d48c548a1 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1060,8 +1060,13 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
@inline def tpdPos(transformed: Tree) = typedPos(tree.pos, mode, pt)(transformed)
@inline def tpd(transformed: Tree) = typed(transformed, mode, pt)
- @inline def warnValueDiscard(): Unit =
- if (!isPastTyper && settings.warnValueDiscard) context.warning(tree.pos, "discarded non-Unit value")
+ @inline def warnValueDiscard(): Unit = if (!isPastTyper && settings.warnValueDiscard) {
+ def isThisTypeResult = (tree, tree.tpe) match {
+ case (Apply(Select(receiver, _), _), SingleType(_, sym)) => sym == receiver.symbol
+ case _ => false
+ }
+ if (!isThisTypeResult) context.warning(tree.pos, "discarded non-Unit value")
+ }
@inline def warnNumericWiden(): Unit =
if (!isPastTyper && settings.warnNumericWiden) context.warning(tree.pos, "implicit numeric widening")
diff --git a/src/repl/scala/tools/nsc/MainGenericRunner.scala b/src/repl/scala/tools/nsc/MainGenericRunner.scala
index a09e797e07..894157ff6c 100644
--- a/src/repl/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/repl/scala/tools/nsc/MainGenericRunner.scala
@@ -49,10 +49,6 @@ class MainGenericRunner {
def isI = !settings.loadfiles.isDefault
def dashi = settings.loadfiles.value
- // Deadlocks on startup under -i unless we disable async.
- if (isI)
- settings.Yreplsync.value = true
-
def combinedCode = {
val files = if (isI) dashi map (file => File(file).slurp()) else Nil
val str = if (isE) List(dashe) else Nil
@@ -98,7 +94,7 @@ class MainGenericRunner {
if (!command.ok)
errorFn(f"%n$shortUsageMsg")
else if (shouldStopWithInfo)
- errorFn(command getInfoMessage sampleCompiler, isFailure = false)
+ errorFn(command.getInfoMessage(sampleCompiler), isFailure = false)
else
run()
}
diff --git a/test/files/pos/t9020.scala b/test/files/pos/t9020.scala
index 16e31e2572..c77a63cb1a 100644
--- a/test/files/pos/t9020.scala
+++ b/test/files/pos/t9020.scala
@@ -8,3 +8,9 @@ test/files/pos/t9020.scala:2: warning: discarded non-Unit value
^
one warning found
*/
+
+trait DiscardThis {
+ import collection.mutable.ListBuffer
+ val b = ListBuffer.empty[String]
+ def add(s: String): Unit = b += s
+}