Files
kotlin-fork/compiler/testData/codegen/box/super/unqualifiedSuper.kt
T
dnpetrov 046189087a 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
2015-06-18 14:16:34 +03:00

67 lines
1.8 KiB
Kotlin
Vendored

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"
}