aboutsummaryrefslogtreecommitdiff
path: root/tests/neg/tailcall/tailrec-2.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-04-04 12:14:43 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-04-11 14:51:20 +0200
commit6ebf6e2c3ef270f226a0fb42ebd59d24449942cf (patch)
tree66c35ac55cb4d4aad5c09d5a074894e682aabdd7 /tests/neg/tailcall/tailrec-2.scala
parent4a3b96282584c77c85ae51f5d29cf7c6082cd7fb (diff)
downloaddotty-6ebf6e2c3ef270f226a0fb42ebd59d24449942cf.tar.gz
dotty-6ebf6e2c3ef270f226a0fb42ebd59d24449942cf.tar.bz2
dotty-6ebf6e2c3ef270f226a0fb42ebd59d24449942cf.zip
TailRec phase and tests for it.
Ported tailcall phase from scalac with such changes: - all transformation is done in the phase itself (previously half of the work was done in backend) - it is now able to run before uncurry - it is now a treeTransform - renamed to tailrec to make it more obvious that this phase transforms only recursive calls. For now this is a single phase which speculatively transforms DefDefs. Speculation can be potentially removed by splitting into 2 phases: one detecting which methods should be transformed second performing transformation. But, as transformation requires as same amount of work as detection, I believe it will be simpler to maintain it as a single phase. Conflicts: tests/pos/typers.scala
Diffstat (limited to 'tests/neg/tailcall/tailrec-2.scala')
-rw-r--r--tests/neg/tailcall/tailrec-2.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/neg/tailcall/tailrec-2.scala b/tests/neg/tailcall/tailrec-2.scala
new file mode 100644
index 000000000..d6b8b1355
--- /dev/null
+++ b/tests/neg/tailcall/tailrec-2.scala
@@ -0,0 +1,29 @@
+sealed abstract class Super[+A] {
+ def f[B >: A](mem: List[B]) : List[B]
+ def g(mem: List[_]) = ???
+}
+// This one should fail, target is a supertype
+class Bop1[+A](val element: A) extends Super[A] {
+
+ @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Super[A]).f(mem)
+ @annotation.tailrec final def f1[B >: A](mem: List[B]): List[B] = this.g(mem)
+}
+// These succeed
+class Bop2[+A](val element: A) extends Super[A] {
+ @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Bop2[A]).f(mem)
+}
+object Bop3 extends Super[Nothing] {
+ @annotation.tailrec final def f[B](mem: List[B]): List[B] = (null: Bop3.type).f(mem)
+}
+class Bop4[+A](val element: A) extends Super[A] {
+ @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = Other.f[A].f(mem)
+}
+
+object Other {
+ def f[T] : Bop4[T] = sys.error("")
+}
+
+object Bop {
+ def m1[A] : Super[A] = sys.error("")
+ def m2[A] : Bop2[A] = sys.error("")
+}