diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java index c0d17868bd8..980895c04ef 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java @@ -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) { diff --git a/compiler/testData/codegen/bytecodeText/noNumberCheckCast.kt b/compiler/testData/codegen/bytecodeText/noNumberCheckCast.kt new file mode 100644 index 00000000000..1ae6b24b34d --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/noNumberCheckCast.kt @@ -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 \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index ac82ecabe8f..f3594f79070 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -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");