[FIR] Allow declarations to override parts of non-trivial intersection

A class can inherit two declarations that are compatible from the
overridability standpoint and are therefore combined to a non-trivial
intersection.
At the same time, the class can declare a member declaration that
only overrides one of the intersection's members.
In this case, we break up the intersection and only add the overridden
parts to the declared member's direct overridden list.

If the class doesn't override the intersection, it exists as
intersection override, like before.

#KT-65487 Fixed
This commit is contained in:
Kirill Rakhman
2024-02-15 18:00:48 +01:00
committed by Space Team
parent 889182629e
commit 26fae9e83a
34 changed files with 1399 additions and 42 deletions
@@ -0,0 +1,38 @@
// FULL_JDK
// SCOPE_DUMP: B1:remove, B2:remove
// FILE: Java1.java
public interface Java1 {
Boolean remove(Integer element);
}
// FILE: testRemove.kt
import java.util.*
// CONFLICTING_JVM_DECLARATIONS in K1 is only reported with old backend, not with K1.
class B1 : ArrayList<Int>(), Java1 {
override fun remove(element: Int?): Boolean {
return false
}
}
// CONFLICTING_JVM_DECLARATIONS in K1 is only reported with old backend, not with K1.
class B2 : ArrayList<Int>(), Java1 {
}
// FILE: Java2.java
public interface Java2 {
Character get(Integer i);
}
// FILE: MyString.java
public abstract class MyString implements CharSequence {
@Override
public char charAt(int i) {
return 'c';
}
}
// FILE: testRenamed.kt
abstract class B3 : MyString(), Java2 {
override fun get(i: Int?): Char? = null
}
@@ -0,0 +1,25 @@
B1:
[Source]: public open override fun remove(element: R|kotlin/Int?|): R|kotlin/Boolean| from Use site scope of /B1 [id: 0]
[Enhancement]: public abstract fun remove(element: R|kotlin/Int!|): R|kotlin/Boolean!| from Java enhancement scope for /Java1 [id: 1]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|@EnhancedNullability kotlin/Int|): R|kotlin/Boolean| from Use site scope of /B1 [id: 0]
B2:
[IntersectionOverride]: public open override fun remove(p0: R|@EnhancedNullability kotlin/Int|): R|kotlin/Boolean| from Use site scope of /B2 [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|@EnhancedNullability kotlin/Int|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/ArrayList] for type B2 [id: 1]
[Enhancement]: public open fun remove(p0: R|@EnhancedNullability E|): R|kotlin/Boolean| from Java enhancement scope for java/util/ArrayList [id: 2]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/AbstractList] for type java/util/ArrayList<E> [id: 3]
[IntersectionOverride]: public open override fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Java enhancement scope for java/util/AbstractList [id: 4]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/AbstractCollection] for type java/util/AbstractList<E> [id: 5]
[Enhancement]: public open fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Java enhancement scope for java/util/AbstractCollection [id: 6]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableCollection] for type java/util/AbstractCollection<E> [id: 7]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 8]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableList] for type java/util/AbstractList<E> [id: 9]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableList [id: 10]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|E|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableCollection] for type kotlin/collections/MutableList<E> [id: 11]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 8]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|E|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableList] for type java/util/ArrayList<E> [id: 12]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableList [id: 10]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|E|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableCollection] for type kotlin/collections/MutableList<E> [id: 11]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 8]
[Enhancement]: public abstract fun remove(element: R|kotlin/Int!|): R|kotlin/Boolean!| from Java enhancement scope for /Java1 [id: 13]
@@ -0,0 +1,38 @@
// FULL_JDK
// SCOPE_DUMP: B1:remove, B2:remove
// FILE: Java1.java
public interface Java1 {
Boolean remove(Integer element);
}
// FILE: testRemove.kt
import java.util.*
// CONFLICTING_JVM_DECLARATIONS in K1 is only reported with old backend, not with K1.
class <!CONFLICTING_JVM_DECLARATIONS!>B1<!> : ArrayList<Int>(), Java1 {
<!CONFLICTING_JVM_DECLARATIONS!>override fun remove(element: Int?): Boolean<!> {
return false
}
}
// CONFLICTING_JVM_DECLARATIONS in K1 is only reported with old backend, not with K1.
class B2 : ArrayList<Int>(), Java1 {
}
// FILE: Java2.java
public interface Java2 {
Character get(Integer i);
}
// FILE: MyString.java
public abstract class MyString implements CharSequence {
@Override
public char charAt(int i) {
return 'c';
}
}
// FILE: testRenamed.kt
abstract class B3 : MyString(), Java2 {
override fun get(i: Int?): Char? = null
}