diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 99e44d73e80..11a987cc2cb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -4232,14 +4232,29 @@ The "returned" value of try expression with no finally is either the last expres putReifiedOperationMarkerIfTypeIsReifiedParameter(type, operationKind, v, this); } + public static void putReifiedOperationMarkerIfTypeIsReifiedParameterWithoutPropagation( + @NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v + ) { + putReifiedOperationMarkerIfTypeIsReifiedParameterImpl(type, operationKind, v, null); + } + public static void putReifiedOperationMarkerIfTypeIsReifiedParameter( @NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v, @NotNull BaseExpressionCodegen codegen + ) { + putReifiedOperationMarkerIfTypeIsReifiedParameterImpl(type, operationKind, v, codegen); + } + + private static void putReifiedOperationMarkerIfTypeIsReifiedParameterImpl( + @NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v, + @Nullable BaseExpressionCodegen codegen ) { Pair typeParameterAndReificationArgument = extractReificationArgument(type); if (typeParameterAndReificationArgument != null && typeParameterAndReificationArgument.getFirst().isReified()) { TypeParameterDescriptor typeParameterDescriptor = typeParameterAndReificationArgument.getFirst(); - codegen.consumeReifiedOperationMarker(typeParameterDescriptor); + if (codegen != null) { + codegen.consumeReifiedOperationMarker(typeParameterDescriptor); + } v.iconst(operationKind.getId()); v.visitLdcInsn(typeParameterAndReificationArgument.getSecond().asString()); v.invokestatic( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt index 2c13783205b..fc93551eb70 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt @@ -166,7 +166,7 @@ abstract class InlineCodegen( var nodeAndSmap: SMAPAndMethodNode? = null try { - nodeAndSmap = createInlineMethodNode(functionDescriptor, jvmSignature, codegen, callDefault, resolvedCall, state, sourceCompiler) + nodeAndSmap = createInlineMethodNode(functionDescriptor, jvmSignature, callDefault, resolvedCall, state, sourceCompiler) endCall(inlineCall(nodeAndSmap, callDefault)) } catch (e: CompilationException) { @@ -467,7 +467,6 @@ abstract class InlineCodegen( internal fun createInlineMethodNode( functionDescriptor: FunctionDescriptor, jvmSignature: JvmMethodSignature, - codegen: BaseExpressionCodegen, callDefault: Boolean, resolvedCall: ResolvedCall<*>?, state: GenerationState, @@ -478,7 +477,6 @@ abstract class InlineCodegen( val arguments = resolvedCall!!.typeArguments val node = createSpecialEnumMethodBody( - codegen, functionDescriptor.name.asString(), arguments.keys.single().defaultType, state.typeMapper diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt index d9894e26476..1f0e86694a1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt @@ -66,7 +66,7 @@ class InlineCodegenForDefaultBody( } override fun genCallInner(callableMethod: Callable, resolvedCall: ResolvedCall<*>?, callDefault: Boolean, codegen: ExpressionCodegen) { - val nodeAndSmap = InlineCodegen.createInlineMethodNode(functionDescriptor, jvmSignature, codegen, callDefault, null, state, sourceCompilerForInline) + val nodeAndSmap = InlineCodegen.createInlineMethodNode(functionDescriptor, jvmSignature, callDefault, null, state, sourceCompilerForInline) val childSourceMapper = InlineCodegen.createNestedSourceMapper(nodeAndSmap, sourceMapper) val node = nodeAndSmap.node diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt index cd3286dca5b..7e434e381fb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt @@ -511,7 +511,6 @@ internal fun isSpecialEnumMethod(functionDescriptor: FunctionDescriptor): Boolea } internal fun createSpecialEnumMethodBody( - codegen: BaseExpressionCodegen, name: String, type: KotlinType, typeMapper: KotlinTypeMapper @@ -520,7 +519,7 @@ internal fun createSpecialEnumMethodBody( val invokeType = typeMapper.mapType(type) val desc = getSpecialEnumFunDescriptor(invokeType, isValueOf) val node = MethodNode(API, Opcodes.ACC_STATIC, "fake", desc, null, null) - ExpressionCodegen.putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.ENUM_REIFIED, InstructionAdapter(node), codegen) + ExpressionCodegen.putReifiedOperationMarkerIfTypeIsReifiedParameterWithoutPropagation(type, ReifiedTypeInliner.OperationKind.ENUM_REIFIED, InstructionAdapter(node)) if (isValueOf) { node.visitInsn(Opcodes.ACONST_NULL) node.visitVarInsn(Opcodes.ALOAD, 0) diff --git a/compiler/testData/codegen/boxInline/enum/kt18254.kt b/compiler/testData/codegen/boxInline/enum/kt18254.kt new file mode 100644 index 00000000000..eb5cf04573c --- /dev/null +++ b/compiler/testData/codegen/boxInline/enum/kt18254.kt @@ -0,0 +1,17 @@ +// FILE: 1.kt +// WITH_RUNTIME +package test + +inline fun stub() {} + +enum class Z { + OK +} + +// FILE: 2.kt +// NO_CHECK_LAMBDA_INLINING +import test.* + +fun box(): String { + return { enumValueOf("OK").name } () +} diff --git a/compiler/testData/codegen/boxInline/enum/valueOf.kt b/compiler/testData/codegen/boxInline/enum/valueOf.kt index 85d4e64100b..5a9f2420163 100644 --- a/compiler/testData/codegen/boxInline/enum/valueOf.kt +++ b/compiler/testData/codegen/boxInline/enum/valueOf.kt @@ -2,8 +2,8 @@ // WITH_RUNTIME package test -inline fun > myValueOf(): String { - return enumValueOf("OK").name +inline fun > myValueOf(): String { + return enumValueOf("OK").name } enum class Z { diff --git a/compiler/testData/codegen/boxInline/enum/valueOfChainCapturedType.kt b/compiler/testData/codegen/boxInline/enum/valueOfChainCapturedType.kt index 48e1b314d51..74b5f0f3bb5 100644 --- a/compiler/testData/codegen/boxInline/enum/valueOfChainCapturedType.kt +++ b/compiler/testData/codegen/boxInline/enum/valueOfChainCapturedType.kt @@ -2,8 +2,8 @@ // WITH_RUNTIME package test -inline fun > myValueOf(): String { - return myValueOf2() +inline fun > myValueOf(): String { + return myValueOf2() } inline fun > myValueOf2(): String { diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 35e3c2045dd..800367fa20c 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -1484,6 +1484,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli doTest(fileName); } + @TestMetadata("kt18254.kt") + public void testKt18254() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt"); + doTest(fileName); + } + @TestMetadata("valueOf.kt") public void testValueOf() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt"); diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index ecbed87601d..ff7ba43d85b 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1484,6 +1484,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC doTest(fileName); } + @TestMetadata("kt18254.kt") + public void testKt18254() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt"); + doTest(fileName); + } + @TestMetadata("valueOf.kt") public void testValueOf() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index e8ee9f3a891..572f970d132 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -1484,6 +1484,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("kt18254.kt") + public void testKt18254() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt"); + doTest(fileName); + } + @TestMetadata("valueOf.kt") public void testValueOf() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 6abfcb97863..f2f117c102d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1484,6 +1484,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("kt18254.kt") + public void testKt18254() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt"); + doTest(fileName); + } + @TestMetadata("valueOf.kt") public void testValueOf() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/EnumValuesInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/EnumValuesInlineTestsGenerated.java index ebb60fa1f28..4fafcd861cb 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/EnumValuesInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/EnumValuesInlineTestsGenerated.java @@ -42,6 +42,12 @@ public class EnumValuesInlineTestsGenerated extends AbstractEnumValuesInlineTest doTest(fileName); } + @TestMetadata("kt18254.kt") + public void testKt18254() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt"); + doTest(fileName); + } + @TestMetadata("valueOf.kt") public void testValueOf() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");