diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-11-03 11:11:28 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-11-03 11:11:28 +1000 |
commit | c6c58071a785af3a55e7e51339461e86c58ae876 (patch) | |
tree | 5df1084d4db8b2b10dadb61be6e1cc1c87624106 /test/files/run/t8893b.scala | |
parent | cae09d760d8778c03d09957786522d766430b218 (diff) | |
download | scala-c6c58071a785af3a55e7e51339461e86c58ae876.tar.gz scala-c6c58071a785af3a55e7e51339461e86c58ae876.tar.bz2 scala-c6c58071a785af3a55e7e51339461e86c58ae876.zip |
SI-8893 Test tailcall transform for mix of tail/non-tail recursion
Another excellent test suggestion by Dear Reviewer.
After tail calls, the transform results in:
```
def tick(i: Int): Unit = {
<synthetic> val _$this: Test.type = Test.this;
_tick(_$this: Test.type, i: Int){
if (i.==(0))
()
else
if (i.==(42))
{
Test.this.tick(0);
_tick(Test.this, i.-(1).asInstanceOf[Int]())
}
else
_tick(Test.this, i.-(1).asInstanceOf[Int]()).asInstanceOf[Unit]()
}
};
```
We test this by mostly exercising the tail-recursive code path with
a level of recursion that would overflow the stack if we weren't
using jumps.
Diffstat (limited to 'test/files/run/t8893b.scala')
-rw-r--r-- | test/files/run/t8893b.scala | 15 |
1 files changed, 15 insertions, 0 deletions
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) + } +} |