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 fddf9908ab3..5b31b9facc8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineIntrinsics.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineIntrinsics.kt @@ -84,6 +84,7 @@ private fun createSpecialEnumMethodBody( Opcodes.INVOKESTATIC, ENUM_TYPE.internalName, "valueOf", Type.getMethodDescriptor(ENUM_TYPE, JAVA_CLASS_TYPE, JAVA_STRING_TYPE), false ) + node.visitTypeInsn(Opcodes.CHECKCAST, ENUM_TYPE.internalName) } else { node.visitInsn(Opcodes.ICONST_0) node.visitTypeInsn(Opcodes.ANEWARRAY, ENUM_TYPE.internalName) 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 37202f6eafc..b1fb4fed56c 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 @@ -3193,6 +3193,11 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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_valueOf.kt b/compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt new file mode 100644 index 00000000000..b1aa1a3cab1 --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt @@ -0,0 +1,42 @@ +// 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 cond() = true + +inline fun , reified Y : Enum> process(name: String) { + val z = try { + enumValueOf(name) + } catch (e: Exception) { + enumValueOf(name) + } + + 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 1aa8a6b0ae3..7a0365fe772 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -3193,6 +3193,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 310d58f2c68..1c48c85cda2 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3193,6 +3193,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 2ccf85904fd..18867122408 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -3193,6 +3193,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 dbb6198aa3b..8794b95bdf1 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3193,6 +3193,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 53b54a2c27a..c4433b9a51d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java @@ -3193,6 +3193,11 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 09a8fc8d10e..445651b0c64 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java @@ -3193,6 +3193,11 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 899cb346bae..1ab6edd9f32 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 @@ -2908,6 +2908,11 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 c2091d7a3ef..a31621e3dba 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 @@ -2908,6 +2908,11 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.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 403b9ed4797..cf9bf9f6da8 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 @@ -2908,6 +2908,11 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest { runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); } + @TestMetadata("kt35511_try_valueOf.kt") + public void testKt35511_try_valueOf() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try_valueOf.kt"); + } + @TestMetadata("kt7017.kt") public void testKt7017() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt7017.kt");