summaryrefslogtreecommitdiff
path: root/test/files/run/elidable.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-02-22 19:54:36 -0800
committerPaul Phillips <paulp@improving.org>2012-02-22 20:09:40 -0800
commit06384c052ec31db4bd094b949bed0f3cb3fb644b (patch)
tree221fe6e2905ebfdf186cc7c828c729ea65450789 /test/files/run/elidable.scala
parenta983f2b30c352f3d62f0ac615044dcd45b1b1618 (diff)
downloadscala-06384c052ec31db4bd094b949bed0f3cb3fb644b.tar.gz
scala-06384c052ec31db4bd094b949bed0f3cb3fb644b.tar.bz2
scala-06384c052ec31db4bd094b949bed0f3cb3fb644b.zip
Reworked and restored elidable.
Found a better elidable implementation which is robust against other parts of the compiler doing their things. Calls to elidable methods are replaced with zero of the same type. Elidable methods themselves remain in place, but with their body replaced with a zero of the method return type. Thus is everything to be found where it is expected to be found, but nothing will be found where nothing ought to be found. Nothing of course will never be found.
Diffstat (limited to 'test/files/run/elidable.scala')
-rw-r--r--test/files/run/elidable.scala73
1 files changed, 71 insertions, 2 deletions
diff --git a/test/files/run/elidable.scala b/test/files/run/elidable.scala
index 264efbad59..a2f29d2caf 100644
--- a/test/files/run/elidable.scala
+++ b/test/files/run/elidable.scala
@@ -1,16 +1,85 @@
import annotation._
import elidable._
+trait T {
+ @elidable(FINEST) def f1()
+ @elidable(SEVERE) def f2()
+ @elidable(FINEST) def f3() = assert(false, "Should have been elided.")
+ def f4()
+}
+
+class C extends T {
+ def f1() = println("Good for me, I was not elided. C.f1")
+ def f2() = println("Good for me, I was not elided. C.f2")
+ @elidable(FINEST) def f4() = assert(false, "Should have been elided.")
+}
+
+object O {
+ @elidable(FINEST) def f1() = assert(false, "Should have been elided.")
+ @elidable(INFO) def f2() = assert(false, "Should have been elided.")
+ @elidable(SEVERE) def f3() = println("Good for me, I was not elided. O.f3")
+ @elidable(INFO) def f4 = assert(false, "Should have been elided (no parens).")
+}
+
object Test {
@elidable(FINEST) def f1() = assert(false, "Should have been elided.")
@elidable(INFO) def f2() = assert(false, "Should have been elided.")
- @elidable(SEVERE) def f3() = println("Good for me, I was not elided.")
+ @elidable(SEVERE) def f3() = println("Good for me, I was not elided. Test.f3")
@elidable(INFO) def f4 = assert(false, "Should have been elided (no parens).")
-
+
+ @elidable(FINEST) def f5() = {}
+ @elidable(FINEST) def f6() = true
+ @elidable(FINEST) def f7() = 1:Byte
+ @elidable(FINEST) def f8() = 1:Short
+ @elidable(FINEST) def f9() = 1:Char
+ @elidable(FINEST) def fa() = 1
+ @elidable(FINEST) def fb() = 1l
+ @elidable(FINEST) def fc() = 1.0f
+ @elidable(FINEST) def fd() = 1.0
+ @elidable(FINEST) def fe() = "s"
+
def main(args: Array[String]): Unit = {
f1()
f2()
f3()
f4
+ O.f1()
+ O.f2()
+ O.f3()
+ O.f4
+
+ val c = new C
+ c.f1()
+ c.f2()
+ c.f3()
+ c.f4()
+
+ // make sure a return value is still available when eliding a call
+ println(f5())
+ println(f6())
+ println(f7())
+ println(f8())
+ println(f9().toInt)
+ println(fa())
+ println(fb())
+ println(fc())
+ println(fd())
+ println(fe())
+
+ // this one won't show up in the output because a call to f1 is elidable when accessed through T
+ (c:T).f1()
+
+ // Test whether the method definitions are still available.
+ List("Test", "Test$", "O", "O$", "C", "T") foreach { className =>
+ List("f1", "f2", "f3", "f4") foreach { methodName =>
+ Class.forName(className).getMethod(methodName)
+ }
+ }
+ List("Test", "Test$") foreach { className =>
+ List("f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe") foreach { methodName =>
+ Class.forName(className).getMethod(methodName)
+ }
+ }
+ Class.forName("T$class").getMethod("f3", classOf[T])
}
}