[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:
committed by
Space Team
parent
889182629e
commit
26fae9e83a
@@ -0,0 +1,50 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: Base.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface Base {
|
||||
Base foo(@NotNull String name);
|
||||
}
|
||||
|
||||
// FILE: Derived.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface Derived extends Base {
|
||||
@Override
|
||||
@NotNull Derived foo(@Nullable String name);
|
||||
}
|
||||
|
||||
// FILE: Impl.kt
|
||||
abstract class Impl : Base {
|
||||
override fun foo(name: String): Base = this
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
abstract class ImplDerived : Impl(), Derived {
|
||||
abstract override fun foo(name: String?): Derived
|
||||
}
|
||||
|
||||
abstract class DerivedImpl : Derived, Impl() {
|
||||
abstract override fun foo(name: String?): Derived
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x1: ImplDerived = object : ImplDerived() {
|
||||
override fun foo(name: String?): Derived = this
|
||||
}
|
||||
x1.foo("")
|
||||
(x1 as Base).foo("")
|
||||
(x1 as Derived).foo("")
|
||||
(x1 as Impl).foo("")
|
||||
|
||||
val x2: DerivedImpl = object : DerivedImpl() {
|
||||
override fun foo(name: String?): Derived = this
|
||||
}
|
||||
x2.foo("")
|
||||
(x2 as Base).foo("")
|
||||
(x2 as Derived).foo("")
|
||||
(x2 as Impl).foo("")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user