From 6d2449f066e1146f4dd6305dc96a096d98830d53 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Thu, 12 Jul 2007 15:01:25 +0000 Subject: Fixed bug #1205 to optimize even more tail calls. --- test/files/run/tailcalls.check | 2 ++ test/files/run/tailcalls.scala | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'test') diff --git a/test/files/run/tailcalls.check b/test/files/run/tailcalls.check index e1e23c4ae1..2bf399ec54 100644 --- a/test/files/run/tailcalls.check +++ b/test/files/run/tailcalls.check @@ -50,3 +50,5 @@ 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 diff --git a/test/files/run/tailcalls.scala b/test/files/run/tailcalls.scala index 8b198b53a0..9e714b979b 100644 --- a/test/files/run/tailcalls.scala +++ b/test/files/run/tailcalls.scala @@ -194,6 +194,27 @@ class TailCall[S](s: S) { } +class FancyTailCalls { + + def tcTryLocal(x: Int, v: Int): Int = { + try { + def loop(n: Int): Int = { + if (n == 0) v else loop(n - 1) + } + loop(x) + } 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) + } + +} class NonTailCall { final def f1(n: Int): Int = try { @@ -348,6 +369,10 @@ object Test { check_success_b("TailCall.b1", TailCall.b1(max), true); check_success_b("TailCall.b2", TailCall.b2(max), true); + + val FancyTailCalls = new FancyTailCalls; + check_success("FancyTailCalls.tcTryLocal", FancyTailCalls.tcTryLocal(max, max), max) + check_success("FancyTailCalls.tcTryCatch", FancyTailCalls.tcTryCatch(max, max), max) } } -- cgit v1.2.3