diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 9e537da079a..d4cb79c672f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -89,6 +89,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import org.jetbrains.org.objectweb.asm.commons.Method; import java.util.*; +import java.util.function.Supplier; import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isInt; import static org.jetbrains.kotlin.codegen.AsmUtil.*; @@ -1432,12 +1433,14 @@ public class ExpressionCodegen extends KtVisitor impleme }); } - public boolean isShouldMarkLineNumbers() { - return shouldMarkLineNumbers; - } - - public void setShouldMarkLineNumbers(boolean shouldMarkLineNumbers) { - this.shouldMarkLineNumbers = shouldMarkLineNumbers; + public T runWithShouldMarkLineNumbers(boolean enable, Supplier operation) { + boolean originalStatus = shouldMarkLineNumbers; + this.shouldMarkLineNumbers = enable; + try { + return operation.get(); + } finally { + this.shouldMarkLineNumbers = originalStatus; + } } public void markStartLineNumber(@NotNull KtElement element) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 8a5465b06c9..de9905ed3db 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -1313,8 +1313,14 @@ public class FunctionCodegen { Label loadArg = new Label(); iv.ifeq(loadArg); - StackValue.local(parameterIndex, type, parameterDescriptor.getType()) - .store(loadStrategy.genValue(parameterDescriptor, codegen), iv); + CallableDescriptor containingDeclaration = parameterDescriptor.getContainingDeclaration(); + codegen.runWithShouldMarkLineNumbers( + !(containingDeclaration instanceof MemberDescriptor) || !((MemberDescriptor) containingDeclaration).isExpect(), + () -> { + StackValue.local(parameterIndex, type, parameterDescriptor.getType()) + .store(loadStrategy.genValue(parameterDescriptor, codegen), iv); + return null; + }); iv.mark(loadArg); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt index 83bb92f5b25..74fc4f0bba7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt @@ -323,30 +323,27 @@ fun FqName.topLevelClassInternalName() = JvmClassName.byClassId(ClassId(parent() fun FqName.topLevelClassAsmType(): Type = Type.getObjectType(topLevelClassInternalName()) fun initializeVariablesForDestructuredLambdaParameters(codegen: ExpressionCodegen, valueParameters: List) { - val savedIsShouldMarkLineNumbers = codegen.isShouldMarkLineNumbers // Do not write line numbers until destructuring happens // (otherwise destructuring variables will be uninitialized in the beginning of lambda) - codegen.isShouldMarkLineNumbers = false + codegen.runWithShouldMarkLineNumbers(false) { + for (parameterDescriptor in valueParameters) { + if (parameterDescriptor !is ValueParameterDescriptorImpl.WithDestructuringDeclaration) continue - for (parameterDescriptor in valueParameters) { - if (parameterDescriptor !is ValueParameterDescriptorImpl.WithDestructuringDeclaration) continue + for (entry in parameterDescriptor.destructuringVariables.filterOutDescriptorsWithSpecialNames()) { + codegen.myFrameMap.enter(entry, codegen.typeMapper.mapType(entry.type)) + } - for (entry in parameterDescriptor.destructuringVariables.filterOutDescriptorsWithSpecialNames()) { - codegen.myFrameMap.enter(entry, codegen.typeMapper.mapType(entry.type)) + val destructuringDeclaration = + (DescriptorToSourceUtils.descriptorToDeclaration(parameterDescriptor) as? KtParameter)?.destructuringDeclaration + ?: error("Destructuring declaration for descriptor $parameterDescriptor not found") + + codegen.initializeDestructuringDeclarationVariables( + destructuringDeclaration, + TransientReceiver(parameterDescriptor.type), + codegen.findLocalOrCapturedValue(parameterDescriptor) ?: error("Local var not found for parameter $parameterDescriptor") + ) } - - val destructuringDeclaration = - (DescriptorToSourceUtils.descriptorToDeclaration(parameterDescriptor) as? KtParameter)?.destructuringDeclaration - ?: error("Destructuring declaration for descriptor $parameterDescriptor not found") - - codegen.initializeDestructuringDeclarationVariables( - destructuringDeclaration, - TransientReceiver(parameterDescriptor.type), - codegen.findLocalOrCapturedValue(parameterDescriptor) ?: error("Local var not found for parameter $parameterDescriptor") - ) } - - codegen.isShouldMarkLineNumbers = savedIsShouldMarkLineNumbers } fun D.unwrapFrontendVersion() = unwrapInitialDescriptorForSuspendFunction() diff --git a/compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt b/compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt new file mode 100644 index 00000000000..edf577e31fd --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt @@ -0,0 +1,40 @@ +// !LANGUAGE: +MultiPlatformProjects +// IGNORE_BACKEND: JVM_IR +// FILE: common.kt + +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES +// A LOT OF LINES + +expect inline fun get(p: String = "OK"): String + +// FILE: platform.kt + +actual inline fun get(p: String): String { + return p +} + +fun box(): String { + return get() +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 348aa59e61b..3385ac7044c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -15855,6 +15855,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); } + @TestMetadata("kt23739.kt") + public void testKt23739() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt"); + } + @TestMetadata("superCall.kt") public void testSuperCall() throws Exception { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 4094ee4e413..cc918fa5cfd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15859,6 +15859,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testKt23239() throws Exception { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); } + + @TestMetadata("kt23739.kt") + public void testKt23739() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt"); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index b70a5465cb6..ebd256e3021 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -15860,6 +15860,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); } + @TestMetadata("kt23739.kt") + public void testKt23739() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt"); + } + @TestMetadata("superCall.kt") public void testSuperCall() throws Exception { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 8a3c376756d..1ebf8229e94 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -12275,6 +12275,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); } + @TestMetadata("kt23739.kt") + public void testKt23739() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt"); + } + @TestMetadata("superCall.kt") public void testSuperCall() throws Exception { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.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 bfd7cd9f93c..5feaadb7726 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 @@ -13325,6 +13325,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); } + @TestMetadata("kt23739.kt") + public void testKt23739() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt"); + } + @TestMetadata("superCall.kt") public void testSuperCall() throws Exception { runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");