KT-5963 Call to super shouldn't require type specification if there is no conflict

Implemented unqualified 'super' type resolution (in BasicExpressionTypingVisitor).

No overload resolution of any kind is involved.
Corresponding supertype is determined by the expected member name only:
- 'super.foo(...)' - function or property (of possibly callable type) 'foo'
- 'super.x' - property 'x'
Supertype should provide a non-abstract implementation of such member.
As a fall-back solution for diagnostics purposes, consider supertypes with abstract implementation of such member.

Diagnostics:
- AMBIGUOUS_SUPER on 'super', if multiple possible supertypes are available;
- ABSTRACT_SUPER_CALL on selector expression, if the only available implementation is abstract.

#KT-5963 Fixed
This commit is contained in:
dnpetrov
2015-06-08 15:35:32 +03:00
parent 46baffc233
commit 046189087a
28 changed files with 1070 additions and 2 deletions
+66
View File
@@ -0,0 +1,66 @@
open class Base() {
open fun baseFun(): String = "Base.baseFun()"
open fun unambiguous(): String = "Base.unambiguous()"
open val baseProp: String
get() = "Base.baseProp"
}
interface Interface {
fun interfaceFun(): String = "Interface.interfaceFun()"
fun unambiguous(): String // NB abstract
}
interface AnotherInterface
interface DerivedInterface: Interface, AnotherInterface {
override fun interfaceFun(): String = "DerivedInterface.interfaceFun()"
override fun unambiguous(): String = "DerivedInterface.unambiguous()"
fun callsFunFromSuperInterface(): String = super.interfaceFun()
}
class Derived : Base(), Interface {
override fun baseFun(): String = "Derived.baseFun()"
override fun unambiguous(): String = "Derived.unambiguous()"
override fun interfaceFun(): String = "Derived.interfaceFun()"
override val baseProp: String
get() = "Derived.baseProp"
fun callsBaseFun(): String = super.baseFun()
fun callsUnambiguousFun(): String = super.unambiguous()
fun getsBaseProp(): String = super.baseProp
fun callsInterfaceFun(): String = super.interfaceFun()
}
fun box(): String {
val d = Derived()
val test1 = d.callsBaseFun()
if (test1 != "Base.baseFun()") return "Failed: d.callsBaseFun()==$test1"
val test2 = d.callsUnambiguousFun()
if (test2 != "Base.unambiguous()") return "Failed: d.callsUnambiguousFun()==$test2"
val test3 = d.getsBaseProp()
if (test3 != "Base.baseProp") return "Failed: d.getsBaseProp()==$test3"
val test4 = d.callsInterfaceFun()
if (test4 != "Interface.interfaceFun()") return "Failed: d.callsInterfaceFun()==$test4"
val di = object : DerivedInterface {}
val test5 = di.callsFunFromSuperInterface()
if (test5 != "Interface.interfaceFun()") return "Failed: di.callsFunFromSuperInterface()==$test5"
return "OK"
}