FIR: Implement FE 1.0 semantics for super unqualified calls

See original logic at org.jetbrains.kotlin.types.expressions.unqualifiedSuper.UnqualifiedSuperKt#resolveUnqualifiedSuperFromExpressionContext

^KT-39070 Fixed
^KT-39599 Related
This commit is contained in:
Denis Zharkov
2020-07-20 12:24:51 +03:00
parent dfc75f3447
commit cd896ae6c8
26 changed files with 285 additions and 82 deletions
@@ -6,6 +6,6 @@ open class A {
class B : A() {
fun g() {
super?.f()
super?.<!UNRESOLVED_REFERENCE!>f<!>()
}
}
}
@@ -2,6 +2,6 @@
enum class E : Cloneable {
A;
override fun clone(): Any {
return super.<!AMBIGUITY!>clone<!>()
return super.<!UNRESOLVED_REFERENCE!>clone<!>()
}
}
@@ -14,7 +14,7 @@ class GenericDerivedClass<T> : GenericBaseClass<T>(), GenericBaseInterface<T> {
override fun bar(x: T): T = super.bar(x)
override fun ambiguous(x: T): T =
super.<!AMBIGUITY!>ambiguous<!>(x)
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>(x)
}
class SpecializedDerivedClass : GenericBaseClass<Int>(), GenericBaseInterface<String> {
@@ -22,9 +22,9 @@ class SpecializedDerivedClass : GenericBaseClass<Int>(), GenericBaseInterface<St
override fun bar(x: String): String = super.bar(x)
override fun ambiguous(x: String): String =
super.ambiguous(x)
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>(x)
override fun ambiguous(x: Int): Int =
super.ambiguous(x)
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>(x)
}
class MixedDerivedClass<T> : GenericBaseClass<Int>(), GenericBaseInterface<T> {
@@ -32,7 +32,7 @@ class MixedDerivedClass<T> : GenericBaseClass<Int>(), GenericBaseInterface<T> {
override fun bar(x: T): T = super.bar(x)
override fun ambiguous(x: Int): Int =
super.ambiguous(x)
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>(x)
override fun ambiguous(x: T): T =
super.ambiguous(x)
}
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>(x)
}
@@ -45,13 +45,13 @@ class Derived : Base(), Interface {
super.prop
fun getAmbiguousSuperProp(): Int =
super.<!AMBIGUITY!>ambiguousProp<!>
super.<!UNRESOLVED_REFERENCE!>ambiguousProp<!>
fun callsFunFromSuperInterface() {
super.bar()
}
fun callsAmbiguousSuperFun() {
super.<!AMBIGUITY!>ambiguous<!>()
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>()
}
}
@@ -34,6 +34,6 @@ class B : A(), I {
}
override fun qux() {
super.<!AMBIGUITY!>qux<!>()
super.<!UNRESOLVED_REFERENCE!>qux<!>()
}
}
@@ -14,8 +14,8 @@ interface InterfaceWithFun {
class DerivedUsingFun : BaseWithCallableProp(), InterfaceWithFun {
fun foo(): String =
super.fn()
super.<!UNRESOLVED_REFERENCE!>fn<!>()
override fun bar(): String =
super.bar()
}
}
@@ -20,9 +20,9 @@ interface AnotherInterface {
interface DerivedInterface: Interface, AnotherInterface {
override fun foo() { super.foo() }
override fun ambiguous() {
super.<!AMBIGUITY!>ambiguous<!>()
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>()
}
override val ambiguousProp: Int
get() = super.<!AMBIGUITY!>ambiguousProp<!>
get() = super.<!UNRESOLVED_REFERENCE!>ambiguousProp<!>
}
@@ -41,13 +41,13 @@ class ClassDerivedFromUnresolved : Base(), Interface, Unresolved {
super.prop
fun getAmbiguousSuperProp(): Int =
super.<!AMBIGUITY!>ambiguousProp<!>
super.<!UNRESOLVED_REFERENCE!>ambiguousProp<!>
fun callsFunFromSuperInterface() {
super.bar()
}
fun callsAmbiguousSuperFun() {
super.<!AMBIGUITY!>ambiguous<!>()
super.<!UNRESOLVED_REFERENCE!>ambiguous<!>()
}
}
@@ -1,29 +0,0 @@
interface A {
fun foo() {}
}
abstract class C : A {
override abstract fun foo()
}
interface Unrelated {
fun foo() {}
}
class Test1 : C(), A {
override fun foo() {
// Abstract 'foo' defined in 'C' wins against non-abstract 'foo' defined in 'A',
// because 'C' is a subclass of 'A' (and 'C::foo' overrides 'A::foo'),
// even though 'A' is explicitly listed in supertypes list for 'D'.
super.foo()
}
}
class Test2 : C(), A, Unrelated {
override fun foo() {
// This is ok, because there's a non-abstract 'foo' in 'Unrelated',
// which is not overridden by abstract 'foo' in 'C'.
super.<!AMBIGUITY!>foo<!>()
super<Unrelated>.foo()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface A {
fun foo() {}
}