diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/TailCalls.scala | 4 | ||||
-rw-r--r-- | test/files/run/tailcalls.check | 1 | ||||
-rw-r--r-- | test/files/run/tailcalls.scala | 22 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index 1fc2f43e3e..02735d0609 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -236,7 +236,9 @@ abstract class TailCalls extends Transform case TypeApply(fun, args) => super.transform(tree) -// throw new RuntimeException("Lonely TypeApply found -- we can only handle them inside Apply(TypeApply()): " + tree + " at: " + unit); + + case Apply(fun, args) if fun.symbol == definitions.Boolean_or => + copy.Apply(tree, fun, transformTrees(args)); case Apply(fun, args) => if (ctx.currentMethod.isFinal && diff --git a/test/files/run/tailcalls.check b/test/files/run/tailcalls.check index 83ea0b3760..49af1207a0 100644 --- a/test/files/run/tailcalls.check +++ b/test/files/run/tailcalls.check @@ -48,3 +48,4 @@ test TailCall.h1 was successful test NonTailCall.f1 0 1 2 was successful test NonTailCall.f2 was successful +test TailCall.b1 was successful diff --git a/test/files/run/tailcalls.scala b/test/files/run/tailcalls.scala index b20fbb20f4..87a14b3f53 100644 --- a/test/files/run/tailcalls.scala +++ b/test/files/run/tailcalls.scala @@ -180,6 +180,9 @@ class TailCall[S](s: S) { aux(x, y, Nil); } + final def b1(x: Int): Boolean = + (x == 1) || b1(x - 1) + def h1(n: Int, v: Int): Int = hP(n, v); private def hP(n: Int, v: Int): Int = if (n == 0) v else hP(n - 1, v - 1); @@ -226,6 +229,23 @@ object Test { Console.println; } + def check_success_b(name: String, closure: => Boolean, expected: Boolean): Unit = { + Console.print("test " + name); + try { + val actual: Boolean = closure; + if (actual == expected) { + Console.print(" was successful"); + } else { + Console.print(" failed: expected "+ expected +", found "+ actual); + } + } catch { + case exception: Throwable => { + Console.print(" raised exception " + exception); + } + } + Console.println; + } + def check_overflow(name: String, closure: => Int): Unit = { Console.print("test " + name); try { @@ -323,6 +343,8 @@ object Test { val NonTailCall = new NonTailCall; check_success("NonTailCall.f1", NonTailCall.f1(2), 0) check_overflow("NonTailCall.f2", NonTailCall.f2(max)) + + check_success_b("TailCall.b1", TailCall.b1(max), true); } } |