Permalink
Browse files

Fix for SI-5215 part 2: generate return value when eliding method calls

  • Loading branch information...
1 parent a6a9684 commit 61c9b4f01d99a81e15391b270bd1b5a895f65ffd @khernyo khernyo committed Feb 20, 2012
@@ -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);
@@ -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
+Good for me, I was not elided. C.f2
+()
+false
+0
+0
+?
+0
+0
+0.0
+0.0
+null
@@ -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])
}
}

0 comments on commit 61c9b4f

Please sign in to comment.