diff options
author | Som Snytt <som.snytt@gmail.com> | 2016-09-10 15:17:49 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2016-09-10 15:17:49 -0700 |
commit | 94518ce0be2ffdb06d1d3f81279fdc05fa568c0b (patch) | |
tree | 4307f49d1d098ed34460f8e648837cecea19f2c2 /src/compiler/scala/tools/nsc/typechecker/Typers.scala | |
parent | 05016d9035ab9b1c866bd9f12fdd0491f1ea0cbb (diff) | |
download | scala-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.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 |
1 files changed, 7 insertions, 2 deletions
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") |