From fa9a3868b7af110c1e463fa2e1f5807cf0eec144 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 17 Sep 2018 10:59:26 +0300 Subject: [PATCH] Make generation of assertions for platform types aware of kotlin types #KT-26859 Fixed --- .../org/jetbrains/kotlin/codegen/AsmUtil.java | 7 ++++--- .../unboxValueFromPlatformType.kt | 18 ++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++++ .../LightAnalysisModeTestGenerated.java | 5 +++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++++ .../semantics/IrJsCodegenBoxTestGenerated.java | 5 +++++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++++ 7 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 263842bf700..913b89e0eb8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -910,19 +910,20 @@ public class AsmUtil { if (state.isCallAssertionsDisabled()) return stackValue; if (runtimeAssertionInfo == null || !runtimeAssertionInfo.getNeedNotNullAssertion()) return stackValue; - return new StackValue(stackValue.type) { + return new StackValue(stackValue.type, stackValue.kotlinType) { @Override public void putSelector(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) { Type innerType = stackValue.type; - stackValue.put(innerType, v); + KotlinType innerKotlinType = stackValue.kotlinType; + stackValue.put(innerType, innerKotlinType, v); if (innerType.getSort() == Type.OBJECT || innerType.getSort() == Type.ARRAY) { v.dup(); v.visitLdcInsn(runtimeAssertionInfo.getMessage()); v.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "checkExpressionValueIsNotNull", "(Ljava/lang/Object;Ljava/lang/String;)V", false); } - StackValue.coerce(innerType, type, v); + StackValue.coerce(innerType, innerKotlinType, type, kotlinType, v); } }; } diff --git a/compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt b/compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt new file mode 100644 index 00000000000..cc7661b339e --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt @@ -0,0 +1,18 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JVM_IR, JS_IR, NATIVE + +inline class SnekDirection(val direction: Int) { + companion object { + val Up = SnekDirection(0) + } +} + +fun testUnbox() : SnekDirection { + val list = arrayListOf(SnekDirection.Up) + return list[0] +} + +fun box(): String { + val a = testUnbox() + return if (a.direction == 0) "OK" else "Fail" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 70d8e29253d..1a4f919837d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11844,6 +11844,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); } + @TestMetadata("unboxValueFromPlatformType.kt") + public void testUnboxValueFromPlatformType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 4a74cde35b3..99a8f7c5797 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11844,6 +11844,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); } + @TestMetadata("unboxValueFromPlatformType.kt") + public void testUnboxValueFromPlatformType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e1099a24583..31972db3525 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11849,6 +11849,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); } + @TestMetadata("unboxValueFromPlatformType.kt") + public void testUnboxValueFromPlatformType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 19281455608..8f9cadd0586 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -10379,6 +10379,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); } + @TestMetadata("unboxValueFromPlatformType.kt") + public void testUnboxValueFromPlatformType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 7d23d3f448e..218e3ba95b5 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -11444,6 +11444,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); } + @TestMetadata("unboxValueFromPlatformType.kt") + public void testUnboxValueFromPlatformType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt");