summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/reflect/internal/TreeGen.scala27
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala26
-rw-r--r--test/files/run/elidable.check2
-rw-r--r--test/files/run/elidable.scala2
4 files changed, 26 insertions, 31 deletions
diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala
index e537c6b83f..cc882ad5ed 100644
--- a/src/compiler/scala/reflect/internal/TreeGen.scala
+++ b/src/compiler/scala/reflect/internal/TreeGen.scala
@@ -250,20 +250,19 @@ abstract class TreeGen {
* var x: T = _
* which is appropriate to the given Type.
*/
- def mkZero(tp: Type): Tree = {
- val tree = tp.typeSymbol match {
- case UnitClass => Literal(Constant())
- case BooleanClass => Literal(Constant(false))
- case FloatClass => Literal(Constant(0.0f))
- case DoubleClass => Literal(Constant(0.0d))
- case ByteClass => Literal(Constant(0.toByte))
- case ShortClass => Literal(Constant(0.toShort))
- case IntClass => Literal(Constant(0))
- case LongClass => Literal(Constant(0L))
- case CharClass => Literal(Constant(0.toChar))
- case _ => Literal(Constant(null))
- }
- tree setType tp
+ def mkZero(tp: Type): Tree = Literal(mkConstantZero(tp)) setType tp
+
+ def mkConstantZero(tp: Type): Constant = tp.typeSymbol match {
+ case UnitClass => Constant(())
+ case BooleanClass => Constant(false)
+ case FloatClass => Constant(0.0f)
+ case DoubleClass => Constant(0.0d)
+ case ByteClass => Constant(0.toByte)
+ case ShortClass => Constant(0.toShort)
+ case IntClass => Constant(0)
+ case LongClass => Constant(0L)
+ case CharClass => Constant(0.toChar)
+ case _ => Constant(null)
}
def mkZeroContravariantAfterTyper(tp: Type): Tree = {
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index e1731c5259..dd65e825c3 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -879,23 +879,19 @@ abstract class GenICode extends SubComponent {
} else if (sym.elisionLevel.exists (_ < settings.elidebelow.value || settings.noassertions.value)) {
// 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
+ debuglog("Eliding call from " + tree.symbol.owner + " to " + sym +
+ " based on its elision threshold of " + sym.elisionLevel.get)
+ if (expectedType.isValueType) {
+ ctx.bb.emit(CONSTANT(global.gen.mkConstantZero(expectedType.toType)), tree.pos)
+ generatedType = expectedType
+ }
+ else {
+ ctx.bb.emit(CONSTANT(Constant(null)), tree.pos)
+ generatedType = NullReference
}
- ctx.bb.emit(CONSTANT(Constant(value)), tree.pos)
- generatedType = if (expectedType.isInstanceOf[ValueTypeKind]) expectedType else NullReference
ctx
- } else { // normal method call
+ }
+ else { // normal method call
debuglog("Gen CALL_METHOD with sym: " + sym + " isStaticSymbol: " + sym.isStaticMember);
val invokeStyle =
if (sym.isStaticMember)
diff --git a/test/files/run/elidable.check b/test/files/run/elidable.check
index 4c0dd3a487..88cf98e0d1 100644
--- a/test/files/run/elidable.check
+++ b/test/files/run/elidable.check
@@ -6,7 +6,7 @@ Good for me, I was not elided. C.f2
false
0
0
-?
+0
0
0
0.0
diff --git a/test/files/run/elidable.scala b/test/files/run/elidable.scala
index e4ea92b72f..a2f29d2caf 100644
--- a/test/files/run/elidable.scala
+++ b/test/files/run/elidable.scala
@@ -59,7 +59,7 @@ object Test {
println(f6())
println(f7())
println(f8())
- println(f9())
+ println(f9().toInt)
println(fa())
println(fb())
println(fc())