diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-11-04 14:55:45 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-11-04 14:55:45 +1000 |
commit | b556b2fdcc7198bffe0ee90c5adc8c9eb3c29e36 (patch) | |
tree | 97aac3270399e4e12c71994099f84b9a048bdf30 /test/files/run | |
parent | d61d007d4852032fcfd339ab2c904a4de6836c4d (diff) | |
parent | c6c58071a785af3a55e7e51339461e86c58ae876 (diff) | |
download | scala-b556b2fdcc7198bffe0ee90c5adc8c9eb3c29e36.tar.gz scala-b556b2fdcc7198bffe0ee90c5adc8c9eb3c29e36.tar.bz2 scala-b556b2fdcc7198bffe0ee90c5adc8c9eb3c29e36.zip |
Merge pull request #4036 from retronym/topic/opt-tail-calls
SI-8893 Restore linear perf in TailCalls with nested matches
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t8893.scala | 40 | ||||
-rw-r--r-- | test/files/run/t8893b.scala | 15 |
2 files changed, 55 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 + } +} diff --git a/test/files/run/t8893b.scala b/test/files/run/t8893b.scala new file mode 100644 index 0000000000..19120871aa --- /dev/null +++ b/test/files/run/t8893b.scala @@ -0,0 +1,15 @@ +// Testing that recursive calls in tail positions are replaced with +// jumps, even though the method contains recursive calls outside +// of the tail position. +object Test { + def tick(i : Int): Unit = + if (i == 0) () + else if (i == 42) { + tick(0) /*not in tail posiiton*/ + tick(i - 1) + } else tick(i - 1) + + def main(args: Array[String]): Unit = { + tick(1000000) + } +} |