diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-01 11:59:13 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-02 16:07:00 +0200 |
commit | c87a9dd1f34cd7afe3fba0edfa1463019eaa78bd (patch) | |
tree | 7500f567d08b96ccbf3a26dd02b76c0ca42aadda /tests | |
parent | 56f01cdf9081b0b221a01e5ae1a9f10e4aa62da9 (diff) | |
download | dotty-c87a9dd1f34cd7afe3fba0edfa1463019eaa78bd.tar.gz dotty-c87a9dd1f34cd7afe3fba0edfa1463019eaa78bd.tar.bz2 dotty-c87a9dd1f34cd7afe3fba0edfa1463019eaa78bd.zip |
First version of inline scheme
To be done: outer accessors
To be done: error positions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/neg/inlineAccess.scala | 15 | ||||
-rw-r--r-- | tests/run/inlineTest.scala | 53 |
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/neg/inlineAccess.scala b/tests/neg/inlineAccess.scala new file mode 100644 index 000000000..cfb1cc06f --- /dev/null +++ b/tests/neg/inlineAccess.scala @@ -0,0 +1,15 @@ +package p { +class C { + protected def f(): Unit = () + + @dotty.annotation.inline + def inl() = f() // error (when inlined): not accessible +} +} + +object Test { + def main(args: Array[String]) = { + val c = new p.C() + c.inl() + } +} diff --git a/tests/run/inlineTest.scala b/tests/run/inlineTest.scala new file mode 100644 index 000000000..feaa43fbb --- /dev/null +++ b/tests/run/inlineTest.scala @@ -0,0 +1,53 @@ +import collection.mutable + +object Test { + + final val monitored = false + + @dotty.annotation.inline + def f(x: Int): Int = x * x + + val hits = new mutable.HashMap[String, Int] { + override def default(key: String): Int = 0 + } + + def record(fn: String, n: Int = 1) = { + if (monitored) { + val name = if (fn.startsWith("member-")) "member" else fn + hits(name) += n + } + } + + @volatile private var stack: List[String] = Nil + + @dotty.annotation.inline + def track[T](fn: String)(op: => T) = + if (monitored) { + stack = fn :: stack + record(fn) + try op + finally stack = stack.tail + } else op + + class Outer { + def f = "Outer.f" + class Inner { + val msg = " Inner" + @dotty.annotation.inline def g = f + @dotty.annotation.inline def h = f ++ this.msg + } + } + + def main(args: Array[String]): Unit = { + println(f(10)) + println(f(f(10))) + + track("hello") { println("") } + + val o = new Outer + val i = new o.Inner + println(i.g) + //println(i.h) + } + +} |