Skip to content

Commit 7a5966f

Browse files
committed
Merge remote-tracking branches 'jsuereth/2.10.0-milestones' and 'szabolcsberecz/SI-5215' into develop
2 parents 6fbd2a8 + 61c9b4f commit 7a5966f

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/compiler/scala/tools/nsc/backend/icode/GenICode.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,20 @@ abstract class GenICode extends SubComponent {
880880
// XXX settings.noassertions.value temporarily retained to avoid
881881
// breakage until a reasonable interface is settled upon.
882882
debuglog("Eliding call from " + tree.symbol.owner + " to " + sym + " based on its elision threshold of " + sym.elisionLevel.get)
883+
val value = expectedType match {
884+
case UNIT => ()
885+
case BOOL => false
886+
case BYTE => 0:Byte
887+
case SHORT => 0:Short
888+
case CHAR => '?'
889+
case INT => 0
890+
case LONG => 0L
891+
case FLOAT => 0.0f
892+
case DOUBLE => 0.0
893+
case _ => null
894+
}
895+
ctx.bb.emit(CONSTANT(Constant(value)), tree.pos)
896+
generatedType = if (expectedType.isInstanceOf[ValueTypeKind]) expectedType else NullReference
883897
ctx
884898
} else { // normal method call
885899
debuglog("Gen CALL_METHOD with sym: " + sym + " isStaticSymbol: " + sym.isStaticMember);

test/files/run/elidable.check

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
Good for me, I was not elided. Test.f3
22
Good for me, I was not elided. O.f3
33
Good for me, I was not elided. C.f1
4-
Good for me, I was not elided. C.f2
4+
Good for me, I was not elided. C.f2
5+
()
6+
false
7+
0
8+
0
9+
?
10+
0
11+
0
12+
0.0
13+
0.0
14+
null

test/files/run/elidable.scala

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ object Test {
2626
@elidable(INFO) def f2() = assert(false, "Should have been elided.")
2727
@elidable(SEVERE) def f3() = println("Good for me, I was not elided. Test.f3")
2828
@elidable(INFO) def f4 = assert(false, "Should have been elided (no parens).")
29-
29+
30+
@elidable(FINEST) def f5() = {}
31+
@elidable(FINEST) def f6() = true
32+
@elidable(FINEST) def f7() = 1:Byte
33+
@elidable(FINEST) def f8() = 1:Short
34+
@elidable(FINEST) def f9() = 1:Char
35+
@elidable(FINEST) def fa() = 1
36+
@elidable(FINEST) def fb() = 1l
37+
@elidable(FINEST) def fc() = 1.0f
38+
@elidable(FINEST) def fd() = 1.0
39+
@elidable(FINEST) def fe() = "s"
40+
3041
def main(args: Array[String]): Unit = {
3142
f1()
3243
f2()
@@ -43,6 +54,18 @@ object Test {
4354
c.f3()
4455
c.f4()
4556

57+
// make sure a return value is still available when eliding a call
58+
println(f5())
59+
println(f6())
60+
println(f7())
61+
println(f8())
62+
println(f9())
63+
println(fa())
64+
println(fb())
65+
println(fc())
66+
println(fd())
67+
println(fe())
68+
4669
// this one won't show up in the output because a call to f1 is elidable when accessed through T
4770
(c:T).f1()
4871

@@ -52,6 +75,11 @@ object Test {
5275
Class.forName(className).getMethod(methodName)
5376
}
5477
}
78+
List("Test", "Test$") foreach { className =>
79+
List("f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe") foreach { methodName =>
80+
Class.forName(className).getMethod(methodName)
81+
}
82+
}
5583
Class.forName("T$class").getMethod("f3", classOf[T])
5684
}
5785
}

0 commit comments

Comments
 (0)