Skip to content

Commit

Permalink
Merge pull request #1892 from retronym/ticket/6479
Browse files Browse the repository at this point in the history
SI-6479 Don't lift try exprs in label arguments.
  • Loading branch information
paulp committed Jan 15, 2013
2 parents 621f7a5 + 9cc61f3 commit 6f3ea77
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/compiler/scala/tools/nsc/transform/UnCurry.scala
Expand Up @@ -621,11 +621,13 @@ abstract class UnCurry extends InfoTransform
case Apply(fn, args) => case Apply(fn, args) =>
if (fn.symbol == Object_synchronized && shouldBeLiftedAnyway(args.head)) if (fn.symbol == Object_synchronized && shouldBeLiftedAnyway(args.head))
transform(treeCopy.Apply(tree, fn, List(liftTree(args.head)))) transform(treeCopy.Apply(tree, fn, List(liftTree(args.head))))
else else {
withNeedLift(true) { val needLift = needTryLift || !fn.symbol.isLabel // SI-6749, no need to lift in args to label jumps.
withNeedLift(needLift) {
val formals = fn.tpe.paramTypes val formals = fn.tpe.paramTypes
treeCopy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, fn.symbol, args, formals))) treeCopy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, fn.symbol, args, formals)))
} }
}


case Assign(Select(_, _), _) => case Assign(Select(_, _), _) =>
withNeedLift(true) { super.transform(tree) } withNeedLift(true) { super.transform(tree) }
Expand Down
56 changes: 56 additions & 0 deletions test/files/pos/t6479.scala
@@ -0,0 +1,56 @@
object TailrecAfterTryCatch {

@annotation.tailrec
final def good1() {
1 match {
case 2 => {
try {
// return
} catch {
case e: ClassNotFoundException =>
}
good1()
}
}
}

@annotation.tailrec
final def good2() {
//1 match {
// case 2 => {
try {
return
} catch {
case e: ClassNotFoundException =>
}
good2()
// }
//}
}

@annotation.tailrec
final def good3() {
val 1 = 2
try {
return
} catch {
case e: ClassNotFoundException =>
}
good3()
}

@annotation.tailrec
final def bad() {
1 match {
case 2 => {
try {
return
} catch {
case e: ClassNotFoundException =>
}
bad()
}
}
}

}

0 comments on commit 6f3ea77

Please sign in to comment.