Don't generate unnecessary checkcast to java.lang.Number

This commit is contained in:
Mikhael Bogdanov
2016-06-02 11:59:07 +03:00
parent a6cf169646
commit 092be8ca8e
3 changed files with 21 additions and 3 deletions
@@ -396,9 +396,10 @@ public abstract class StackValue {
}
}
else if (fromType.getSort() == Type.OBJECT) {
if (fromType.equals(getType(Boolean.class)) || fromType.equals(getType(Character.class))) {
unbox(unboxType(fromType), v);
coerce(unboxType(fromType), toType, v);
Type unboxedType = unboxPrimitiveTypeOrNull(fromType);
if (unboxedType != null) {
unbox(unboxedType, v);
coerce(unboxedType, toType, v);
}
else {
if (toType.getSort() == Type.BOOLEAN || toType.getSort() == Type.CHAR) {
@@ -0,0 +1,11 @@
fun test() {
val z : Int? = 1
val r = z!! + 1
stubPreventBoxingOptimization(z)
}
fun stubPreventBoxingOptimization(s: Int?) {
s
}
//0 CHECKCAST java/lang/Number
@@ -263,6 +263,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
@TestMetadata("noNumberCheckCast.kt")
public void testNoNumberCheckCast() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/noNumberCheckCast.kt");
doTest(fileName);
}
@TestMetadata("noSuperCheckInDefaultConstuctor.kt")
public void testNoSuperCheckInDefaultConstuctor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/noSuperCheckInDefaultConstuctor.kt");