summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala14
-rw-r--r--test/files/run/elidable.check12
-rw-r--r--test/files/run/elidable.scala30
3 files changed, 54 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index ca00508dc7..e1731c5259 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -880,6 +880,20 @@ abstract class GenICode extends SubComponent {
// XXX settings.noassertions.value temporarily retained to avoid
// breakage until a reasonable interface is settled upon.
debuglog("Eliding call from " + tree.symbol.owner + " to " + sym + " based on its elision threshold of " + sym.elisionLevel.get)
+ val value = expectedType match {
+ case UNIT => ()
+ case BOOL => false
+ case BYTE => 0:Byte
+ case SHORT => 0:Short
+ case CHAR => '?'
+ case INT => 0
+ case LONG => 0L
+ case FLOAT => 0.0f
+ case DOUBLE => 0.0
+ case _ => null
+ }
+ ctx.bb.emit(CONSTANT(Constant(value)), tree.pos)
+ generatedType = if (expectedType.isInstanceOf[ValueTypeKind]) expectedType else NullReference
ctx
} else { // normal method call
debuglog("Gen CALL_METHOD with sym: " + sym + " isStaticSymbol: " + sym.isStaticMember);
diff --git a/test/files/run/elidable.check b/test/files/run/elidable.check
index 9ce2f8c18a..4c0dd3a487 100644
--- a/test/files/run/elidable.check
+++ b/test/files/run/elidable.check
@@ -1,4 +1,14 @@
Good for me, I was not elided. Test.f3
Good for me, I was not elided. O.f3
Good for me, I was not elided. C.f1
-Good for me, I was not elided. C.f2 \ No newline at end of file
+Good for me, I was not elided. C.f2
+()
+false
+0
+0
+?
+0
+0
+0.0
+0.0
+null
diff --git a/test/files/run/elidable.scala b/test/files/run/elidable.scala
index 5015b1470b..e4ea92b72f 100644
--- a/test/files/run/elidable.scala
+++ b/test/files/run/elidable.scala
@@ -26,7 +26,18 @@ object Test {
@elidable(INFO) def f2() = assert(false, "Should have been 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()
@@ -43,6 +54,18 @@ object Test {
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())
+ 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()
@@ -52,6 +75,11 @@ object Test {
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])
}
}