aboutsummaryrefslogtreecommitdiff
path: root/tests/run
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-02 13:52:28 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-02 16:11:21 +0200
commit6f9f29e1f90c017f30a81b0e37f994b5b8cd8507 (patch)
treeb4fc1f8c5146c242f9ccd35700286a613bb20e01 /tests/run
parentb8a117634b636d6255e6233ae1996f6c7b90dcae (diff)
downloaddotty-6f9f29e1f90c017f30a81b0e37f994b5b8cd8507.tar.gz
dotty-6f9f29e1f90c017f30a81b0e37f994b5b8cd8507.tar.bz2
dotty-6f9f29e1f90c017f30a81b0e37f994b5b8cd8507.zip
Recursive inlining tests
pos/power inlines with alomst no extraneous boilerplate. neg/power gives an error that maximal numbers of inlines was exceeded.
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/power.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/run/power.scala b/tests/run/power.scala
new file mode 100644
index 000000000..2bb66fa8d
--- /dev/null
+++ b/tests/run/power.scala
@@ -0,0 +1,17 @@
+object Test {
+
+ @dotty.annotation.inline
+ def power(x: Double, n: Int): Double =
+ if (n == 0) 1.0
+ else if (n == 1) x
+ else {
+ val y = power(x, n / 2)
+ if (n % 2 == 0) y * y else y * y * x
+ }
+
+ def main(args: Array[String]): Unit = {
+ println(power(2.0, 10))
+ def x = 2.0
+ println(power(x, 11))
+ }
+}