From 6c56d71a1712836364826b7b80cceb4c12c102a9 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 21 Sep 2011 21:13:36 +0000 Subject: Fixed issue with warnings in IDE. "Pure expression in statement position" is hopefully a lot quieter now. Review by dragos. --- .../scala/tools/nsc/typechecker/Typers.scala | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2ae867f990..37652a1790 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2236,6 +2236,17 @@ trait Typers extends Modes with Adaptations { case Some(imp1: Import) => imp1 case None => log("unhandled import: "+imp+" in "+unit); imp } + private def isWarnablePureExpression(tree: Tree) = tree match { + case EmptyTree | Literal(Constant(())) => false + case _ => + !tree.containsErrorOrIsErrorTyped() && (treeInfo isPureExpr tree) && { + val sym = tree.symbol + (sym == null) || !(sym.isModule || sym.isLazy) || { + debuglog("'Pure' but side-effecting expression in statement position: " + tree) + false + } + } + } def typedStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = { val inBlock = exprOwner == context.owner @@ -2270,22 +2281,11 @@ trait Typers extends Modes with Adaptations { else result } else result - result1 match { - case EmptyTree | Literal(Constant(())) => result1 - case tree if tree.containsError() => result1 - case tree => - if (treeInfo isPureExpr result1) { - val sym = result1.symbol - if (sym != null && (sym.isModule || sym.isLazy)) { - debuglog("'Pure' but side-effecting expression in statement position: " + result1) - } - else context.warning(stat.pos, - "a pure expression does nothing in statement position; " + - "you may be omitting necessary parentheses" - ) - } - result1 - } + if (isWarnablePureExpression(result1)) context.warning(stat.pos, + "a pure expression does nothing in statement position; " + + "you may be omitting necessary parentheses" + ) + result1 } } } -- cgit v1.2.3