Permalink
Browse files

SI-6686 drop valdef unused in flatMapCond's block

  • Loading branch information...
1 parent b47bb0f commit b92396b57912f040d8f536b8a60b844ff586ff0d @adriaanm adriaanm committed Jan 30, 2013
@@ -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]
@@ -20,7 +20,6 @@ class SameBytecode {
val x1 = Foo(1, "a")
if (x1.ne(null)) {
if (x1.x.isInstanceOf[String]) {
- val x3 = x1.x.asInstanceOf[String]
return x1.y
}
}
@@ -14,7 +14,6 @@ class SameBytecode {
if (x1.isInstanceOf[Foo]) {
val x3 = x1.asInstanceOf[Foo]
if (x3.x.isInstanceOf[String]) {
- val x4 = x3.x.asInstanceOf[String]
val x = ()
return
}
@@ -16,7 +16,6 @@ class SameBytecode {
def b: String = {
val x1 = Foo(1, "a")
if (x1.ne(null)) {
- val x3 = x1.x
return x1.y
}
Oops, something went wrong.

2 comments on commit b92396b

@scala-jenkins

Job pr-rangepos-per-commit failed for b92396b (results):


Took 4 min.
sad kitty
to rebuild, comment "PLS REBUILD/pr-rangepos-per-commit@b92396b"on PR #2112

@scala-jenkins

Job pr-checkin-per-commit failed for b92396b (results):


Took 4 min.
sad kitty
to rebuild, comment "PLS REBUILD/pr-checkin-per-commit@b92396b"on PR #2112

Please sign in to comment.