diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/RedundantCheckCastElimination.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/RedundantCheckCastElimination.kt index e9175d6b794..591c89c28d2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/RedundantCheckCastElimination.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/RedundantCheckCastElimination.kt @@ -28,7 +28,8 @@ import org.jetbrains.org.objectweb.asm.tree.TypeInsnNode class RedundantCheckCastEliminationMethodTransformer : MethodTransformer() { override fun transform(internalClassName: String, methodNode: MethodNode) { val insns = methodNode.instructions.toArray() - if (!insns.any { it.opcode == Opcodes.CHECKCAST }) return + if (!insns.any { it.opcode == Opcodes.CHECKCAST}) return + if (insns.any { ReifiedTypeInliner.isOperationReifiedMarker(it) }) return val redundantCheckCasts = ArrayList() @@ -36,7 +37,6 @@ class RedundantCheckCastEliminationMethodTransformer : MethodTransformer() { for (i in insns.indices) { val valueType = frames[i]?.top()?.type ?: continue val insn = insns[i] - if (ReifiedTypeInliner.isOperationReifiedMarker(insn.previous)) continue if (insn is TypeInsnNode) { val insnType = Type.getObjectType(insn.desc) 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 c6ff391f81c..37202f6eafc 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 @@ -3183,6 +3183,16 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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.kt b/compiler/testData/codegen/boxInline/reified/kt35511.kt new file mode 100644 index 00000000000..05d1b04a348 --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt35511.kt @@ -0,0 +1,35 @@ +// JVM_TARGET: 1.8 +// FILE: 1.kt +// WITH_RUNTIME + +package test + +open class Base(val name: String) +class A(name: String) : Base(name) +class B(name: String) : Base(name) + +var result = "fail" + +fun foo(base: Array) { + result = base[0].name +} + +fun cond() = true + +inline fun process(a: Base) { + val z = if (cond()) + arrayOf(a as T) + else + arrayOf(a as Y) + foo(z) +} + + +// FILE: 2.kt +import test.* + +fun box(): String { + process(A("OK")) + + return result +} diff --git a/compiler/testData/codegen/boxInline/reified/kt35511_try.kt b/compiler/testData/codegen/boxInline/reified/kt35511_try.kt new file mode 100644 index 00000000000..cd22f34d66d --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt35511_try.kt @@ -0,0 +1,37 @@ +// JVM_TARGET: 1.8 +// FILE: 1.kt +// WITH_RUNTIME + +package test + +open class Base(val name: String) +class A(name: String) : Base(name) +class B(name: String) : Base(name) + +var result = "fail" + +fun foo(base: Array) { + result = base[0].name +} + +fun cond() = true + +inline fun process(a: Base) { + val z = try { + arrayOf(a as T) + } catch (e: Exception) { + arrayOf(a as Y) + } + + foo(z) +} + + +// FILE: 2.kt +import test.* + +fun box(): String { + process(B("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 aed950f648c..1aa8a6b0ae3 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -3183,6 +3183,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 31a0f820c06..310d58f2c68 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3183,6 +3183,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 431effe77dd..2ccf85904fd 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -3183,6 +3183,16 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 139b9134649..dbb6198aa3b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3183,6 +3183,16 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 88cdfa57675..53b54a2c27a 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java @@ -3183,6 +3183,16 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 ea64d503989..09a8fc8d10e 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java @@ -3183,6 +3183,16 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 902eb405405..899cb346bae 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 @@ -2898,6 +2898,16 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 f5935646cd0..c2091d7a3ef 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 @@ -2898,6 +2898,16 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.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 6f46048e3fa..403b9ed4797 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 @@ -2898,6 +2898,16 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest { runTest("compiler/testData/codegen/boxInline/reified/kt18977.kt"); } + @TestMetadata("kt35511.kt") + public void testKt35511() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511.kt"); + } + + @TestMetadata("kt35511_try.kt") + public void testKt35511_try() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt35511_try.kt"); + } + @TestMetadata("kt7017.kt") public void testKt7017() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt7017.kt");