[FE] Skip delegation descriptors during default params matching

^KT-61163 Fixed
Review: https://jetbrains.team/p/kt/reviews/11599/timeline

They can be safely skiped because we check overridden descriptors
anyway.

IMO, it's a bug that delegated descriptors are copied with default
params. But it's much harder problem, and my IMO can easily be wrong for
some weird reason.
This commit is contained in:
Nikita Bobko
2023-08-11 12:21:58 +02:00
committed by Space Team
parent 8a576438ce
commit 577d0db3f1
8 changed files with 102 additions and 2 deletions
@@ -103,6 +103,18 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
runTest("compiler/testData/diagnostics/tests/multiplatform/checkNoActualForExpectInLastModule.kt");
}
@Test
@TestMetadata("defaultParams_inheritanceByDelegation_negative.kt")
public void testDefaultParams_inheritanceByDelegation_negative() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultParams_inheritanceByDelegation_negative.kt");
}
@Test
@TestMetadata("defaultParams_inheritanceByDelegation_positive.kt")
public void testDefaultParams_inheritanceByDelegation_positive() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultParams_inheritanceByDelegation_positive.kt");
}
@Test
@TestMetadata("expectAbstractToString.kt")
public void testExpectAbstractToString() throws Exception {
@@ -103,6 +103,18 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/tests/multiplatform/checkNoActualForExpectInLastModule.kt");
}
@Test
@TestMetadata("defaultParams_inheritanceByDelegation_negative.kt")
public void testDefaultParams_inheritanceByDelegation_negative() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultParams_inheritanceByDelegation_negative.kt");
}
@Test
@TestMetadata("defaultParams_inheritanceByDelegation_positive.kt")
public void testDefaultParams_inheritanceByDelegation_positive() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultParams_inheritanceByDelegation_positive.kt");
}
@Test
@TestMetadata("expectAbstractToString.kt")
public void testExpectAbstractToString() throws Exception {
@@ -256,7 +256,7 @@ class FirExpectActualMatchingContextImpl private constructor(
// Tests work even if you don't filter out fake-overrides. Filtering fake-overrides is needed because
// the returned descriptors are compared by `equals`. And `equals` for fake-overrides is weird.
// I didn't manage to invent a test that would check this condition
.filter { !it.isSubstitutionOrIntersectionOverride }
.filter { !it.isSubstitutionOrIntersectionOverride && it.origin != FirDeclarationOrigin.Delegated }
}
}
}
@@ -207,7 +207,7 @@ class ClassicExpectActualMatchingContext(
// Tests work even if you don't filter out fake-overrides. Filtering fake-overrides is needed because
// the returned descriptors are compared by `equals`. And `equals` for fake-overrides is weird.
// I didn't manage to invent a test that would check this condition
.filter { it.kind.isReal }
.filter { it.kind != CallableMemberDescriptor.Kind.FAKE_OVERRIDE && it.kind != CallableMemberDescriptor.Kind.DELEGATION }
override fun CallableSymbolMarker.isAnnotationConstructor(): Boolean {
val descriptor = safeAsDescriptor<ConstructorDescriptor>() ?: return false
@@ -0,0 +1,22 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt
interface I {
fun f(x: Int = 5) = x
}
expect class E : I {
override fun f(x: Int): Int
}
expect class E2 : I {
override fun f(x: Int): Int
}
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
actual class E(i: I) : I by i
actual class E2(i: I) : I by i {
actual override fun f(x: Int): Int = x
}
@@ -0,0 +1,21 @@
// MODULE: m1-common
// FILE: common.kt
<!INCOMPATIBLE_MATCHING{JVM}!>expect class E {
<!INCOMPATIBLE_MATCHING{JVM}!>fun f(x: Int): Int<!>
}<!>
expect class E2 {
fun f(x: Int): Int
}
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
interface I {
fun f(x: Int = 5) = x
}
actual class <!NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS!>E<!>(i: I) : I by i
actual class E2(i: I) : I by i {
actual override fun f<!ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS!>(x: Int)<!> = x
}
@@ -0,0 +1,21 @@
// MODULE: m1-common
// FILE: common.kt
expect class E {
fun f(x: Int): Int
}
expect class E2 {
fun f(x: Int): Int
}
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
interface I {
fun f(x: Int = 5) = x
}
actual class <!NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS!>E<!>(i: I) : I by i
actual class E2(i: I) : I by i {
actual override fun f<!ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS!>(x: Int)<!> = x
}
@@ -22794,6 +22794,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/multiplatform/checkNoActualForExpectInLastModule.kt");
}
@Test
@TestMetadata("defaultParams_inheritanceByDelegation_negative.kt")
public void testDefaultParams_inheritanceByDelegation_negative() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultParams_inheritanceByDelegation_negative.kt");
}
@Test
@TestMetadata("defaultParams_inheritanceByDelegation_positive.kt")
public void testDefaultParams_inheritanceByDelegation_positive() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultParams_inheritanceByDelegation_positive.kt");
}
@Test
@TestMetadata("expectAbstractToString.kt")
public void testExpectAbstractToString() throws Exception {