diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-11-02 21:39:41 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-11-02 21:39:41 +1000 |
commit | cae09d760d8778c03d09957786522d766430b218 (patch) | |
tree | 4620d2e85785b55ccfed95c993b5897bac1fb9aa | |
parent | 10b0d216a3e3b011103a7c939fabe441440f9aa1 (diff) | |
download | scala-cae09d760d8778c03d09957786522d766430b218.tar.gz scala-cae09d760d8778c03d09957786522d766430b218.tar.bz2 scala-cae09d760d8778c03d09957786522d766430b218.zip |
SI-8893 Test case to show that tailrec continues to work
As suggested during code review, this test checks that
the tailcalls phase recurses appropriately below a method
that doesn and does not itself tail call. The test case is
based on the pattern of code that to trigger super-linear
performance in this transform.
-rw-r--r-- | test/files/run/t8893.scala | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/files/run/t8893.scala b/test/files/run/t8893.scala new file mode 100644 index 0000000000..6fef8ae912 --- /dev/null +++ b/test/files/run/t8893.scala @@ -0,0 +1,40 @@ +import annotation.tailrec + +object Test { + def a(): Option[String] = Some("a") + + def test1: Any = { + a() match { + case Some(b1) => + a() match { + case Some(b2) => + @tailrec + def tick(i: Int): Unit = if (i < 0) () else tick(i - 1) + tick(10000000) // testing that this doesn't SOE + case None => None + } + case None => None + } + } + + def test2: Any = { + a() match { + case Some(b1) => + a() match { + case Some(b2) => + @tailrec + def tick(i: Int): Unit = if (i < 0) () else tick(i - 1) + tick(10000000) // testing that this doesn't SOE + case None => test1 + } + case None => + test1 // not a tail call + test1 + } + } + + def main(args: Array[String]) { + test1 + test2 + } +} |