From c13f38f6dfed54fd3e0f0dc2f18c529718155144 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 27 Jan 2021 17:19:01 +0100 Subject: [PATCH] Support proper frame maps for enumValues --- .../kotlin/resolve/jvm/AsmTypes.java | 1 - .../kotlin/codegen/inline/inlineIntrinsics.kt | 1 + ...FirBlackBoxInlineCodegenTestGenerated.java | 5 ++ .../boxInline/reified/kt35511_try_values.kt | 46 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 5 ++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 ++ .../IrBlackBoxInlineCodegenTestGenerated.java | 5 ++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 ++ ...JvmIrAgainstOldBoxInlineTestGenerated.java | 5 ++ ...JvmOldAgainstIrBoxInlineTestGenerated.java | 5 ++ .../IrJsCodegenInlineES6TestGenerated.java | 5 ++ .../IrJsCodegenInlineTestGenerated.java | 5 ++ .../JsCodegenInlineTestGenerated.java | 5 ++ 13 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt diff --git a/compiler/backend.common.jvm/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java b/compiler/backend.common.jvm/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java index 76ba76d30b3..9aa3dc97f62 100644 --- a/compiler/backend.common.jvm/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java +++ b/compiler/backend.common.jvm/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java @@ -14,7 +14,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; public class AsmTypes { private static final Map, Type> TYPES_MAP = new HashMap<>(); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineIntrinsics.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineIntrinsics.kt index 5b31b9facc8..73e0bcaef8d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineIntrinsics.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineIntrinsics.kt @@ -88,6 +88,7 @@ private fun createSpecialEnumMethodBody( } else { node.visitInsn(Opcodes.ICONST_0) node.visitTypeInsn(Opcodes.ANEWARRAY, ENUM_TYPE.internalName) + node.visitTypeInsn(Opcodes.CHECKCAST, AsmUtil.getArrayType(ENUM_TYPE).internalName) } node.visitInsn(Opcodes.ARETURN) node.visitMaxs(if (isValueOf) 3 else 2, if (isValueOf) 1 else 0) diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java index b1fb4fed56c..b73838b8baf 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java @@ -3198,6 +3198,11 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt b/compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt new file mode 100644 index 00000000000..267282689c4 --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt @@ -0,0 +1,46 @@ +// JVM_TARGET: 1.8 +// FILE: 1.kt +// WITH_RUNTIME + +package test + +enum class Base(val value: String) { + OK("OK"), + B("FAIL"); +} + +enum class Base2(val value: String) { + A("OK2"), + B("FAIL2"); +} + +var result = "fail" + +fun foo(base: Enum<*>) { + result = base.name +} + +fun foo(base: Array>) { + result = base[0].name +} + +fun cond() = true + +inline fun , reified Y : Enum> process(a: String) { + val z = try { + enumValues() + } catch (e: Exception) { + enumValues() + } + + foo(z) +} + +// FILE: 2.kt +import test.* + +fun box(): String { + process("OK") + + return result +} diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 7a0365fe772..a9df0cd2606 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -3198,6 +3198,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 1c48c85cda2..73294a7e251 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3198,6 +3198,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 18867122408..2fbb43a410f 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -3198,6 +3198,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index 8794b95bdf1..6dd8afbe7d1 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3198,6 +3198,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java index c4433b9a51d..f6403790381 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java @@ -3198,6 +3198,11 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java index 445651b0c64..60430f67eb4 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java @@ -3198,6 +3198,11 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java index 1ab6edd9f32..e3ffa614aef 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java @@ -2913,6 +2913,11 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt7017.kt") public void testKt7017() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt7017.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java index a31621e3dba..e6a9c24f270 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java @@ -2913,6 +2913,11 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt7017.kt") public void testKt7017() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt7017.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java index cf9bf9f6da8..a403a626e25 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java @@ -2913,6 +2913,11 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest { runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); } + @TestMetadata("kt35511_try_values.kt") + public void testKt35511_try_values() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_values.kt"); + } + @TestMetadata("kt7017.kt") public void testKt7017() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt7017.kt");