diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt index aeefb9cd138..e385d00676d 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.backend.common.BackendContext import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.IrElementVisitorVoidWithContext import org.jetbrains.kotlin.backend.common.ScopeWithIr -import org.jetbrains.kotlin.backend.common.descriptors.* +import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName import org.jetbrains.kotlin.backend.common.ir.* import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement +import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.Scope import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl @@ -411,9 +412,9 @@ class LocalDeclarationsLowering( 0, localClassContext.capturedValueToField.map { (capturedValue, field) -> IrSetFieldImpl( - irClass.startOffset, irClass.endOffset, field.symbol, - IrGetValueImpl(irClass.startOffset, irClass.endOffset, irClass.thisReceiver!!.symbol), - constructorContext.irGet(irClass.startOffset, irClass.endOffset, capturedValue)!!, + UNDEFINED_OFFSET, UNDEFINED_OFFSET, field.symbol, + IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irClass.thisReceiver!!.symbol), + constructorContext.irGet(UNDEFINED_OFFSET, UNDEFINED_OFFSET, capturedValue)!!, context.irBuiltIns.unitType, STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE ) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt index babd9ad3cb6..43d3c78c2b7 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt @@ -185,7 +185,6 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext) private fun createConstructor(): IrConstructor = functionReferenceClass.addConstructor { - setSourceRange(irFunctionReference) origin = JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE returnType = functionReferenceClass.defaultType isPrimary = true @@ -227,6 +226,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext) private fun createInvokeMethod(receiverVar: IrValueDeclaration?): IrSimpleFunction = functionReferenceClass.addFunction { + setSourceRange(if (isLambda) callee else irFunctionReference) name = superMethod.owner.name returnType = callee.returnType isSuspend = callee.isSuspend @@ -244,8 +244,9 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext) } valueParameters += valueParameterMap.values - body = context.createIrBuilder(symbol).irBlockBody(startOffset, endOffset) { - callee.body?.statements?.forEach { statement -> + val calleeBody = callee.body as IrBlockBody + body = context.createIrBuilder(symbol).irBlockBody(calleeBody.startOffset, calleeBody.endOffset) { + calleeBody.statements.forEach { statement -> +statement.transform(object : IrElementTransformerVoid() { override fun visitGetValue(expression: IrGetValue): IrExpression { val replacement = valueParameterMap[expression.symbol.owner] diff --git a/compiler/testData/debug/stepping/callableReference.kt b/compiler/testData/debug/stepping/callableReference.kt new file mode 100644 index 00000000000..1285100c185 --- /dev/null +++ b/compiler/testData/debug/stepping/callableReference.kt @@ -0,0 +1,23 @@ +// FILE: test.kt +fun box() { + var x = false + f { + x = true + } +} + +fun f(block: () -> Unit) { + block() +} + +// LINENUMBERS +// TestKt.box():3 +// TestKt.box():4 +// TestKt.f(kotlin.jvm.functions.Function0):10 +// TestKt$box$1.invoke():5 +// TestKt$box$1.invoke():6 +// TestKt$box$1.invoke():-1 +// TestKt$box$1.invoke():-1 +// TestKt.f(kotlin.jvm.functions.Function0):10 +// TestKt.f(kotlin.jvm.functions.Function0):11 +// TestKt.box():7 diff --git a/compiler/testData/debug/stepping/inlineCallableReference.kt b/compiler/testData/debug/stepping/inlineCallableReference.kt new file mode 100644 index 00000000000..63eb22b1731 --- /dev/null +++ b/compiler/testData/debug/stepping/inlineCallableReference.kt @@ -0,0 +1,20 @@ +// FILE: test.kt +fun box() { + var x = false + f { + x = true + } +} + +inline fun f(block: () -> Unit) { + block() +} + +// LINENUMBERS +// TestKt.box():3 +// TestKt.box():4 +// TestKt.box():10 +// TestKt.box():5 +// TestKt.box():6 +// TestKt.box():11 +// TestKt.box():7 diff --git a/compiler/testData/debug/stepping/inlineNamedCallableReference.kt b/compiler/testData/debug/stepping/inlineNamedCallableReference.kt new file mode 100644 index 00000000000..7cc78cbfe3e --- /dev/null +++ b/compiler/testData/debug/stepping/inlineNamedCallableReference.kt @@ -0,0 +1,20 @@ +// FILE: test.kt +fun box() { + var x = false + f(::g) +} + +inline fun f(block: () -> Unit) { + block() +} + +fun g() {} + +// LINENUMBERS +// TestKt.box():3 +// TestKt.box():4 +// TestKt.box():8 +// TestKt.box():4 +// TestKt.g():11 +// TestKt.box():9 +// TestKt.box():5 diff --git a/compiler/testData/debug/stepping/namedCallableReference.kt b/compiler/testData/debug/stepping/namedCallableReference.kt new file mode 100644 index 00000000000..62b4f4a12cc --- /dev/null +++ b/compiler/testData/debug/stepping/namedCallableReference.kt @@ -0,0 +1,23 @@ +// FILE: test.kt +fun box() { + var x = false + f(::g) +} + +fun f(block: () -> Unit) { + block() +} + +fun g() {} + +// LINENUMBERS +// TestKt.box():3 +// TestKt.box():4 +// TestKt.f(kotlin.jvm.functions.Function0):8 +// TestKt.g():11 +// TestKt$box$1.invoke():4 +// TestKt$box$1.invoke():-1 +// TestKt$box$1.invoke():-1 +// TestKt.f(kotlin.jvm.functions.Function0):8 +// TestKt.f(kotlin.jvm.functions.Function0):9 +// TestKt.box():5 diff --git a/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt b/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt index 9c272ccbebc..392aa085d4c 100644 --- a/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt +++ b/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt @@ -12,5 +12,4 @@ fun foo(f: () -> Unit) { f() } -// IGNORE_BACKEND: JVM_IR // 2 6 9 12 13 3 4 7 8 diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java index 5587aafd089..2bc19dbd169 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java @@ -31,6 +31,12 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/debug/stepping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("callableReference.kt") + public void testCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/callableReference.kt"); + } + @Test @TestMetadata("conjunction.kt") public void testConjunction() throws Exception { @@ -55,6 +61,24 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest { runTest("compiler/testData/debug/stepping/IfTrueThenFalse.kt"); } + @Test + @TestMetadata("inlineCallableReference.kt") + public void testInlineCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/inlineCallableReference.kt"); + } + + @Test + @TestMetadata("inlineNamedCallableReference.kt") + public void testInlineNamedCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/inlineNamedCallableReference.kt"); + } + + @Test + @TestMetadata("namedCallableReference.kt") + public void testNamedCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/namedCallableReference.kt"); + } + @Test @TestMetadata("recursion.kt") public void testRecursion() throws Exception { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java index cfc5cb1e63a..e5bcf1ff1a5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java @@ -31,6 +31,12 @@ public class SteppingTestGenerated extends AbstractSteppingTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/debug/stepping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("callableReference.kt") + public void testCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/callableReference.kt"); + } + @Test @TestMetadata("conjunction.kt") public void testConjunction() throws Exception { @@ -55,6 +61,24 @@ public class SteppingTestGenerated extends AbstractSteppingTest { runTest("compiler/testData/debug/stepping/IfTrueThenFalse.kt"); } + @Test + @TestMetadata("inlineCallableReference.kt") + public void testInlineCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/inlineCallableReference.kt"); + } + + @Test + @TestMetadata("inlineNamedCallableReference.kt") + public void testInlineNamedCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/inlineNamedCallableReference.kt"); + } + + @Test + @TestMetadata("namedCallableReference.kt") + public void testNamedCallableReference() throws Exception { + runTest("compiler/testData/debug/stepping/namedCallableReference.kt"); + } + @Test @TestMetadata("recursion.kt") public void testRecursion() throws Exception {