summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-09-21 21:13:36 +0000
committerPaul Phillips <paulp@improving.org>2011-09-21 21:13:36 +0000
commit6c56d71a1712836364826b7b80cceb4c12c102a9 (patch)
tree91f4523cc94c4fdf762f7fb1cf4bea851822ef8c /src
parent3491b3d79dccf43cf1c25b7607d4df169fdbace5 (diff)
downloadscala-6c56d71a1712836364826b7b80cceb4c12c102a9.tar.gz
scala-6c56d71a1712836364826b7b80cceb4c12c102a9.tar.bz2
scala-6c56d71a1712836364826b7b80cceb4c12c102a9.zip
Fixed issue with warnings in IDE.
"Pure expression in statement position" is hopefully a lot quieter now. Review by dragos.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala32
1 files changed, 16 insertions, 16 deletions
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
}
}
}