diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 50b5a3e91cb..f31767c6771 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -569,7 +569,9 @@ class Fir2IrDeclarationStorage( val result = declareIrSimpleFunction(signature) { symbol -> classifierStorage.preCacheTypeParameters(function, symbol) irFactory.createFunction( - startOffset, endOffset, updatedOrigin, symbol, + if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else startOffset, + if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else endOffset, + updatedOrigin, symbol, name, components.visibilityConverter.convertToDescriptorVisibility(visibility), simpleFunction?.modality ?: Modality.FINAL, function.returnTypeRef.toIrType(), diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt index 370848ed483..47e7db70570 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl +import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.JvmNames.JVM_DEFAULT_CLASS_ID @@ -236,8 +237,8 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I superFunction: IrSimpleFunction, callTypeCanBeNullable: Boolean ): IrBlockBody { - val startOffset = irField.startOffset - val endOffset = irField.endOffset + val startOffset = SYNTHETIC_OFFSET + val endOffset = SYNTHETIC_OFFSET val body = irFactory.createBlockBody(startOffset, endOffset) val irCall = IrCallImpl( startOffset, diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBytecodeTextTestGenerated.java index 238d147ed4b..cd9a48ec29d 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBytecodeTextTestGenerated.java @@ -4534,6 +4534,12 @@ public class FirLightTreeBytecodeTextTestGenerated extends AbstractFirLightTreeB KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/lineNumbers"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("delegationToList.kt") + public void testDelegationToList() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/lineNumbers/delegationToList.kt"); + } + @Test @TestMetadata("ifConsts.kt") public void testIfConsts() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeSteppingTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeSteppingTestGenerated.java index 4900badff54..90874c05b92 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeSteppingTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeSteppingTestGenerated.java @@ -157,6 +157,12 @@ public class FirLightTreeSteppingTestGenerated extends AbstractFirLightTreeStepp runTest("compiler/testData/debug/stepping/defaultParameter.kt"); } + @Test + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + runTest("compiler/testData/debug/stepping/delegation.kt"); + } + @Test @TestMetadata("enum.kt") public void testEnum() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBytecodeTextTestGenerated.java index ea3e140dfb9..75b297b4828 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBytecodeTextTestGenerated.java @@ -4534,6 +4534,12 @@ public class FirPsiBytecodeTextTestGenerated extends AbstractFirPsiBytecodeTextT KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/lineNumbers"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("delegationToList.kt") + public void testDelegationToList() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/lineNumbers/delegationToList.kt"); + } + @Test @TestMetadata("ifConsts.kt") public void testIfConsts() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiSteppingTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiSteppingTestGenerated.java index 78aba6cd43f..3c25995da24 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiSteppingTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiSteppingTestGenerated.java @@ -157,6 +157,12 @@ public class FirPsiSteppingTestGenerated extends AbstractFirPsiSteppingTest { runTest("compiler/testData/debug/stepping/defaultParameter.kt"); } + @Test + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + runTest("compiler/testData/debug/stepping/delegation.kt"); + } + @Test @TestMetadata("enum.kt") public void testEnum() throws Exception { diff --git a/compiler/testData/codegen/bytecodeText/lineNumbers/delegationToList.kt b/compiler/testData/codegen/bytecodeText/lineNumbers/delegationToList.kt new file mode 100644 index 00000000000..e8481276351 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/lineNumbers/delegationToList.kt @@ -0,0 +1,14 @@ +// IGNORE_BACKEND: JVM + + + +class DelegatedList : List by ArrayList() + +// There's 1 line number in each of the following methods: +// - ()V +// - size()I +// - contains(Ljava/lang/Object;)Z +// - get(I)Ljava/lang/Object; +// - indexOf(Ljava/lang/Object;)I +// - lastIndexOf(Ljava/lang/Object;)I +// 6 LINENUMBER 5 diff --git a/compiler/testData/debug/stepping/delegation.kt b/compiler/testData/debug/stepping/delegation.kt new file mode 100644 index 00000000000..6a3cdea01a9 --- /dev/null +++ b/compiler/testData/debug/stepping/delegation.kt @@ -0,0 +1,41 @@ +// FILE: test.kt + +interface I { + fun f() +} + +object O : I { + override fun f() { + Unit + } +} + +class C : I by O + +fun box() { + val c = C() + c.f() +} + +// EXPECTATIONS JVM JVM_IR +// test.kt:16 box +// test.kt:13 +// EXPECTATIONS JVM +// test.kt:7 +// EXPECTATIONS JVM JVM_IR +// test.kt:16 box +// test.kt:17 box +// test.kt:10 f +// test.kt:-1 f +// test.kt:18 box + +// EXPECTATIONS JS_IR +// test.kt:16 box +// test.kt:13 +// test.kt:7 +// test.kt:13 +// test.kt:17 box +// test.kt:1 f +// test.kt:10 f +// test.kt:1 f +// test.kt:18 box diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegateToTwoTraits.fir.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegateToTwoTraits.fir.kt deleted file mode 100644 index 048432b3c70..00000000000 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegateToTwoTraits.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -interface Foo { - fun foo(l: List) -} - -interface Bar { - fun foo(l: List) -} - -class Baz(f: Foo, b: Bar) : - Foo by f, - Bar by b { -} diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegateToTwoTraits.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegateToTwoTraits.kt index 3a71b9296d1..3b835eb44ce 100644 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegateToTwoTraits.kt +++ b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegateToTwoTraits.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER interface Foo { diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationAndOwnMethod.fir.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationAndOwnMethod.fir.kt deleted file mode 100644 index 2d1a43b0ca0..00000000000 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationAndOwnMethod.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -interface Foo { - fun foo(l: List) -} - -class Bar(f: Foo): Foo by f { - fun foo(l: List) {} -} diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationAndOwnMethod.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationAndOwnMethod.kt index 6f79f5982e9..27738d26a2c 100644 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationAndOwnMethod.kt +++ b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationAndOwnMethod.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER interface Foo { diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.fir.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.fir.kt deleted file mode 100644 index b920f0798e3..00000000000 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -interface Foo { - fun foo(l: List) { - - } -} - -class Bar(f: Foo): Foo by f { - fun foo(l: List) {} -} - -class BarOther(f: Foo): Foo by f { - override fun foo(l: List) {} -} diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.kt index 3c1d75b4ebc..9b608a382c0 100644 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.kt +++ b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER interface Foo { diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl_ir.fir.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl_ir.fir.kt deleted file mode 100644 index 8a69c8bd746..00000000000 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl_ir.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -// TARGET_BACKEND: JVM_IR - -interface A { - fun foo(l: List) -} - -interface B { - fun foo(l: List) {} -} - -class C(f: A): A by f, B - -class D(f: A): A by f, B diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl_ir.kt b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl_ir.kt index 8bb10a9d25f..bb9b9a72862 100644 --- a/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl_ir.kt +++ b/compiler/testData/diagnostics/testsWithJvmBackend/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl_ir.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // TARGET_BACKEND: JVM_IR @@ -11,4 +12,4 @@ interface B { class C(f: A): A by f, B -class D(f: A): A by f, B \ No newline at end of file +class D(f: A): A by f, B diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java index a826bfad324..7029e8a05e3 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java @@ -4162,6 +4162,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/lineNumbers"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("delegationToList.kt") + public void testDelegationToList() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/lineNumbers/delegationToList.kt"); + } + @Test @TestMetadata("ifConsts.kt") public void testIfConsts() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java index 9309a25007b..29dae45e039 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java @@ -4534,6 +4534,12 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/lineNumbers"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("delegationToList.kt") + public void testDelegationToList() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/lineNumbers/delegationToList.kt"); + } + @Test @TestMetadata("ifConsts.kt") public void testIfConsts() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithBytecodeInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithBytecodeInlinerTestGenerated.java index 71736b38b40..74448edfc28 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithBytecodeInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithBytecodeInlinerTestGenerated.java @@ -157,6 +157,12 @@ public class IrSteppingWithBytecodeInlinerTestGenerated extends AbstractIrSteppi runTest("compiler/testData/debug/stepping/defaultParameter.kt"); } + @Test + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + runTest("compiler/testData/debug/stepping/delegation.kt"); + } + @Test @TestMetadata("enum.kt") public void testEnum() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithIrInlinerTestGenerated.java index 459641078ac..ef59083a994 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrSteppingWithIrInlinerTestGenerated.java @@ -157,6 +157,12 @@ public class IrSteppingWithIrInlinerTestGenerated extends AbstractIrSteppingWith runTest("compiler/testData/debug/stepping/defaultParameter.kt"); } + @Test + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + runTest("compiler/testData/debug/stepping/delegation.kt"); + } + @Test @TestMetadata("enum.kt") public void testEnum() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/SteppingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/SteppingTestGenerated.java index cd0bad67599..6cfd118e68f 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/SteppingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/SteppingTestGenerated.java @@ -157,6 +157,12 @@ public class SteppingTestGenerated extends AbstractSteppingTest { runTest("compiler/testData/debug/stepping/defaultParameter.kt"); } + @Test + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + runTest("compiler/testData/debug/stepping/delegation.kt"); + } + @Test @TestMetadata("enum.kt") public void testEnum() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsSteppingTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsSteppingTestGenerated.java index 2648c378d5a..d499eadc2ed 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsSteppingTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsSteppingTestGenerated.java @@ -157,6 +157,12 @@ public class IrJsSteppingTestGenerated extends AbstractIrJsSteppingTest { runTest("compiler/testData/debug/stepping/defaultParameter.kt"); } + @Test + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + runTest("compiler/testData/debug/stepping/delegation.kt"); + } + @Test @TestMetadata("enum.kt") public void testEnum() throws Exception {