diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2008-08-08 09:59:26 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2008-08-08 09:59:26 +0000 |
commit | 2d445ad1afe66b8b8fb9139c43f29605eb5a0877 (patch) | |
tree | 09960dee71dc209340bccc06b5d1cdb64133c214 | |
parent | aa1f5a76e4b16035328444cd12e3bc35cc864b09 (diff) | |
download | scala-2d445ad1afe66b8b8fb9139c43f29605eb5a0877.tar.gz scala-2d445ad1afe66b8b8fb9139c43f29605eb5a0877.tar.bz2 scala-2d445ad1afe66b8b8fb9139c43f29605eb5a0877.zip |
Fixed tail-call related issues.
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/TailCalls.scala | 10 | ||||
-rw-r--r-- | test/files/run/tailcalls.check | 2 | ||||
-rw-r--r-- | test/files/run/tailcalls.scala | 16 |
3 files changed, 4 insertions, 24 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index 4ab49b68cc..8c582b1756 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -236,12 +236,10 @@ abstract class TailCalls extends Transform case Return(expr) => super.transform(tree) case Try(block, catches, finalizer) => - if (finalizer == EmptyTree) - super.transform(tree) - else - copy.Try(tree, transform(block, mkContext(ctx, false)), // recursive calls are not in tail position if there is non-empty finally clause - transformTrees(catches, ctx).asInstanceOf[List[CaseDef]], - transform(finalizer, ctx)) + // no calls inside try are in tail position, but keep recursing for more nested functions + copy.Try(tree, transform(block, mkContext(ctx, false)), + transformTrees(catches, mkContext(ctx, false)).asInstanceOf[List[CaseDef]], + transform(finalizer, mkContext(ctx, false))) case Throw(expr) => super.transform(tree) case New(tpt) => super.transform(tree) diff --git a/test/files/run/tailcalls.check b/test/files/run/tailcalls.check index 7ee9280223..e913f2a061 100644 --- a/test/files/run/tailcalls.check +++ b/test/files/run/tailcalls.check @@ -39,7 +39,6 @@ test c.c.c.c.f was successful test TailCall.f1 was successful test TailCall.f2 was successful test TailCall.f3 was successful -test TailCall.f4 was successful test TailCall.g1 was successful test TailCall.g2 was successful test TailCall.g3 was successful @@ -51,5 +50,4 @@ test NonTailCall.f2 was successful test TailCall.b1 was successful test TailCall.b2 was successful test FancyTailCalls.tcTryLocal was successful -test FancyTailCalls.tcTryCatch was successful test FancyTailCalls.differentInstance was successful diff --git a/test/files/run/tailcalls.scala b/test/files/run/tailcalls.scala index 0e158ac39f..1340e8d532 100644 --- a/test/files/run/tailcalls.scala +++ b/test/files/run/tailcalls.scala @@ -158,11 +158,6 @@ class TailCall[S](s: S) { if (n == 0) v else f2[T](n - 1, v - 1); final def f3[T](n: Int, v: Int, ls: List[T]): Int = if (n == 0) v else f3(n - 1, v - 1, ls); - final def f4(n: Int, v: Int): Int = try { - if (n == 0) v else f4(n - 1, v - 1); - } catch { - case e: Throwable => throw e - } final def g1(x: Int, y: Int): Int = { def aux(n: Int, v: Int): Int = @@ -210,15 +205,6 @@ class FancyTailCalls { } finally {} } - final def tcTryCatch(x: Int, v: Int): Int = - try { - if (x == 0) v - else throw new RuntimeException("") - } catch { - case _: RuntimeException => - tcTryCatch(x - 1, v) - } - import FancyTailCalls._ final def differentInstance(n: Int, v: Int): Int = { if (n == 0) v @@ -368,7 +354,6 @@ object Test { check_success("TailCall.f1", TailCall.f1(max, max ), 0) check_success("TailCall.f2", TailCall.f2(max, max ), 0) check_success("TailCall.f3", TailCall.f3(max, max, Nil), 0) - check_success("TailCall.f4", TailCall.f4(max, max ), 0) check_success("TailCall.g1", TailCall.g1(max, max ), 0) check_success("TailCall.g2", TailCall.g2(max, max ), 0) check_success("TailCall.g3", TailCall.g3(max, max, Nil), 0) @@ -384,7 +369,6 @@ object Test { val FancyTailCalls = new FancyTailCalls; check_success("FancyTailCalls.tcTryLocal", FancyTailCalls.tcTryLocal(max, max), max) - check_success("FancyTailCalls.tcTryCatch", FancyTailCalls.tcTryCatch(max, max), max) check_success("FancyTailCalls.differentInstance", FancyTailCalls.differentInstance(max, 42), 42) } } |