diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index aa0651709ee..995ed225f24 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -4587,10 +4587,16 @@ public class ExpressionCodegen extends KtVisitor impleme // We can use the $$delegatedProperties array as in non-inline functions and upon inlining, detect elements at what indices // of that array are used in the inline function body, load the corresponding initializing bytecode from of the // container class (where the PropertyReferenceNImpl instance is created), copy and adapt it at the call site - //noinspection ConstantConditions - StackValue value = context.getFunctionDescriptor().isInline() - ? generatePropertyReference(variable.getDelegate(), variableDescriptor, variableDescriptor, null) - : PropertyCodegen.getDelegatedPropertyMetadata(variableDescriptor, bindingContext); + StackValue value; + if (PropertyCodegen.isDelegatedPropertyWithOptimizedMetadata(variableDescriptor, bindingContext)) { + value = PropertyCodegen.getOptimizedDelegatedPropertyMetadataValue(); + } else if (context.getFunctionDescriptor().isInline()) { + //noinspection ConstantConditions + value = generatePropertyReference(variable.getDelegate(), variableDescriptor, variableDescriptor, null); + } + else { + value = PropertyCodegen.getDelegatedPropertyMetadata(variableDescriptor, bindingContext); + } value.put(K_PROPERTY_TYPE, null, v); metadataVar.storeSelector(K_PROPERTY_TYPE, null, v); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index 1c89ab3d71e..2b450eeaeaf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -564,13 +564,24 @@ public class PropertyCodegen { return codegen.invokeFunction(resolvedCall, receiver); } + public static boolean isDelegatedPropertyWithOptimizedMetadata( + @NotNull VariableDescriptorWithAccessors descriptor, + @NotNull BindingContext bindingContext + ) { + return Boolean.TRUE == bindingContext.get(DELEGATED_PROPERTY_WITH_OPTIMIZED_METADATA, descriptor); + } + + public static @NotNull StackValue getOptimizedDelegatedPropertyMetadataValue() { + return StackValue.constant(null, K_PROPERTY_TYPE); + } + @NotNull public static StackValue getDelegatedPropertyMetadata( @NotNull VariableDescriptorWithAccessors descriptor, @NotNull BindingContext bindingContext ) { - if (Boolean.TRUE == bindingContext.get(DELEGATED_PROPERTY_WITH_OPTIMIZED_METADATA, descriptor)) { - return StackValue.constant(null, K_PROPERTY_TYPE); + if (isDelegatedPropertyWithOptimizedMetadata(descriptor, bindingContext)) { + return getOptimizedDelegatedPropertyMetadataValue(); } Type owner = bindingContext.get(DELEGATED_PROPERTY_METADATA_OWNER, descriptor); diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index f981cd33acf..e94d4b314ff 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -8735,6 +8735,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt"); } + @TestMetadata("kt37204.kt") + public void testKt37204() throws Exception { + runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt"); + } + @TestMetadata("kt4138.kt") public void testKt4138() throws Exception { runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt"); diff --git a/compiler/testData/codegen/box/delegatedProperty/kt37204.kt b/compiler/testData/codegen/box/delegatedProperty/kt37204.kt new file mode 100644 index 00000000000..a4aae28764b --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/kt37204.kt @@ -0,0 +1,22 @@ +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME +// IGNORE_BACKEND_FIR: JVM_IR + +val log = StringBuilder() + +inline fun test() { + val localLazy by lazy { + log.append("localLazy;") + "v;" + } + log.append("test;") + log.append(localLazy) +} + +fun box(): String { + test() + val t = log.toString() + if (t != "test;localLazy;v;") + throw AssertionError(t) + return "OK" +} \ 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 04852d64fb8..3a2ce3705a4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -9880,6 +9880,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt"); } + @TestMetadata("kt37204.kt") + public void testKt37204() throws Exception { + runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt"); + } + @TestMetadata("kt4138.kt") public void testKt4138() throws Exception { runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 15812206a97..42892a65cd0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -9880,6 +9880,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt"); } + @TestMetadata("kt37204.kt") + public void testKt37204() throws Exception { + runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt"); + } + @TestMetadata("kt4138.kt") public void testKt4138() throws Exception { runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 6cc81419924..2c6ca7c33b3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -8735,6 +8735,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt"); } + @TestMetadata("kt37204.kt") + public void testKt37204() throws Exception { + runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt"); + } + @TestMetadata("kt4138.kt") public void testKt4138() throws Exception { runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index fac8aaa8ca4..4f3562e0ffb 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -5729,8 +5729,8 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } @TestMetadata("suspendFunctionIsAs.kt") - public void testSuspendFunctionIsAs_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt", "kotlin.coroutines"); + public void testSuspendFunctionIsAs() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt"); } @TestMetadata("suspendInlineSuspendFinally.kt") @@ -7470,6 +7470,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt"); } + @TestMetadata("kt37204.kt") + public void testKt37204() throws Exception { + runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt"); + } + @TestMetadata("kt4138.kt") public void testKt4138() throws Exception { runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.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 d7e4e92d2ff..057c478e0fe 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 @@ -5729,8 +5729,8 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } @TestMetadata("suspendFunctionIsAs.kt") - public void testSuspendFunctionIsAs_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt", "kotlin.coroutines"); + public void testSuspendFunctionIsAs() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt"); } @TestMetadata("suspendInlineSuspendFinally.kt") @@ -7470,6 +7470,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt"); } + @TestMetadata("kt37204.kt") + public void testKt37204() throws Exception { + runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt"); + } + @TestMetadata("kt4138.kt") public void testKt4138() throws Exception { runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");