K2: do not generate line numbers for delegated members

Psi2ir does not generate them, see
https://github.com/JetBrains/kotlin/blob/1.8.20/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt#L319.

Besides influencing debugger and coverage behavior, it also affects how
conflicting JVM signature diagnostics are reported because they
use offsets to determine which element to report the error on. So after
this change, K1 and K2 behavior is the same in that regard as well.

 #KT-58215 Fixed
This commit is contained in:
Alexander Udalov
2023-05-06 00:11:30 +02:00
committed by Space Team
parent b3aa2dd60f
commit 987e8c25dc
22 changed files with 126 additions and 56 deletions
@@ -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(),
@@ -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,
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -0,0 +1,14 @@
// IGNORE_BACKEND: JVM
class DelegatedList : List<Int> by ArrayList()
// There's 1 line number in each of the following methods:
// - <init>()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
+41
View File
@@ -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 <init>
// EXPECTATIONS JVM
// test.kt:7 <clinit>
// 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 <init>
// test.kt:7 <init>
// test.kt:13 <init>
// test.kt:17 box
// test.kt:1 f
// test.kt:10 f
// test.kt:1 f
// test.kt:18 box
@@ -1,14 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Foo<T> {
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(l: List<T>)<!>
}
interface Bar<T> {
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(l: List<T>)<!>
}
class Baz(f: Foo<String>, b: Bar<Int>) :
Foo<String> by f,
Bar<Int> by b {
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Foo<T> {
@@ -1,9 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Foo<T> {
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(l: List<T>)<!>
}
class Bar(f: Foo<String>): Foo<String> by f {
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(l: List<Int>)<!> {}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Foo<T> {
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Foo<T> {
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(l: List<T>)<!> {
}
}
class Bar(f: Foo<String>): Foo<String> by f {
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(l: List<Int>)<!> {}
}
class BarOther(f: Foo<String>): Foo<String> by f {
override fun foo(l: List<String>) {}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Foo<T> {
@@ -1,14 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// TARGET_BACKEND: JVM_IR
interface A<T> {
<!ACCIDENTAL_OVERRIDE!>fun foo(l: List<T>)<!>
}
interface B {
fun foo(l: List<Int>) {}
}
class C(f: A<String>): A<String> by f, B
<!DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE!>class D<!>(f: A<Int>): A<Int> by f, B
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// TARGET_BACKEND: JVM_IR
@@ -11,4 +12,4 @@ interface B {
class <!ACCIDENTAL_OVERRIDE!>C(f: A<String>)<!>: A<String> by f, B
<!DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE!>class D<!>(f: A<Int>): A<Int> by f, B
<!DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE!>class D<!>(f: A<Int>): A<Int> by f, B
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {