diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.kt index 0f9380a24d0..954497344b3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.kt @@ -26,7 +26,8 @@ class CoercionValue( ) : StackValue(castType, value.canHaveSideEffects()) { override fun putSelector(type: Type, v: InstructionAdapter) { - value.putSelector(castType, v) + value.putSelector(value.type, v) + StackValue.coerce(value.type, castType, v) StackValue.coerce(castType, type, v) } diff --git a/compiler/testData/codegen/boxWithStdlib/intrinsics/charToInt.kt b/compiler/testData/codegen/boxWithStdlib/intrinsics/charToInt.kt new file mode 100644 index 00000000000..371632e071c --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/intrinsics/charToInt.kt @@ -0,0 +1,8 @@ +fun box(): String { + val x: Any = 'A' + var y = 0 + if (x is Char) { + y = x.toInt() + } + return if (y == 65) "OK" else "fail" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index f8012c0beb4..861d4311ea3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -1588,6 +1588,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/intrinsics"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("charToInt.kt") + public void testCharToInt() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/intrinsics/charToInt.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("defaultObjectMapping.kt") public void testDefaultObjectMapping() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/intrinsics/defaultObjectMapping.kt");