summaryrefslogtreecommitdiff
path: root/test/files/neg/tailrec-3.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-10 07:21:56 +0000
committerPaul Phillips <paulp@improving.org>2011-01-10 07:21:56 +0000
commite05dfaeabf430dac8909ff9e5a5911b0c94101ae (patch)
tree397ce22c41c4c5b95390625ef73fcb70cef856b6 /test/files/neg/tailrec-3.scala
parent58b5c24df8ba06c02b92723922bc21381fedeb93 (diff)
downloadscala-e05dfaeabf430dac8909ff9e5a5911b0c94101ae.tar.gz
scala-e05dfaeabf430dac8909ff9e5a5911b0c94101ae.tar.bz2
scala-e05dfaeabf430dac8909ff9e5a5911b0c94101ae.zip
A pretty severe bug in the recognition of tail ...
A pretty severe bug in the recognition of tail call elimination. It turns out that Tailcalls will perform "partial elimination" in situations such as: @annotation.tailrec final def f(x: Int): Int = f(f(x)) The outer call to f1 becomes a jump, but the inner call remains as it was. I implemented @tailrec under the impression that if the optimization had taken place, it had gone all the way. So this is now fixed with a direct examination of the rewritten tree. While I was in there I threw in some improved error reporting: the error positioning is now on the call which is not in tail position rather than the method declaration. Closes #4135, no review.
Diffstat (limited to 'test/files/neg/tailrec-3.scala')
-rw-r--r--test/files/neg/tailrec-3.scala14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/files/neg/tailrec-3.scala b/test/files/neg/tailrec-3.scala
new file mode 100644
index 0000000000..20361658ea
--- /dev/null
+++ b/test/files/neg/tailrec-3.scala
@@ -0,0 +1,14 @@
+import annotation.tailrec
+
+object Test {
+ @tailrec private def quux(xs: List[String]): List[String] = quux(quux(xs))
+ @tailrec private def quux2(xs: List[String]): List[String] = xs match {
+ case x1 :: x2 :: rest => quux2(x1 :: quux2(rest))
+ case _ => Nil
+ }
+ @tailrec private def quux3(xs: List[String]): Boolean = xs match {
+ case x :: xs if quux3(List("abc")) => quux3(xs)
+ case _ => false
+ }
+}
+