summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-01-29 19:16:37 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-01-31 11:00:44 -0800
commitb92396b57912f040d8f536b8a60b844ff586ff0d (patch)
treeda0db6ba2a3674d4d642241b62d2c0a3670014a4 /src
parentb47bb0fe1a0eb2f60f280ef0fa62a6f0be65580b (diff)
downloadscala-b92396b57912f040d8f536b8a60b844ff586ff0d.tar.gz
scala-b92396b57912f040d8f536b8a60b844ff586ff0d.tar.bz2
scala-b92396b57912f040d8f536b8a60b844ff586ff0d.zip
SI-6686 drop valdef unused in flatMapCond's block
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index c6f80c9b20..4b53802d95 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -3792,11 +3792,17 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// nextBinder: T
// next == MatchMonad[U]
// returns MatchMonad[U]
- def flatMapCond(cond: Tree, res: Tree, nextBinder: Symbol, next: Tree): Tree =
- ifThenElseZero(cond, BLOCK(
- VAL(nextBinder) === res,
- next
- ))
+ def flatMapCond(cond: Tree, res: Tree, nextBinder: Symbol, next: Tree): Tree = {
+ val rest =
+ // only emit a local val for `nextBinder` if it's actually referenced in `next`
+ if (next.exists(_.symbol eq nextBinder))
+ BLOCK(
+ VAL(nextBinder) === res,
+ next
+ )
+ else next
+ ifThenElseZero(cond, rest)
+ }
// guardTree: Boolean
// next: MatchMonad[T]