KT-52592 Fix NPE from KProperty.getExtensionDelegate on property delegated to another property; make $delegate methods private

This commit is contained in:
Pavel Mikhailovskii
2022-06-01 11:44:00 +02:00
committed by teamcity
parent 315501debf
commit 3b5179686e
10 changed files with 64 additions and 11 deletions
@@ -11,11 +11,15 @@ object Delegate {
}
val topLevel: Boolean by Delegate
val delegated: Boolean by ::topLevel
val String.extension: Boolean by Delegate
val String.delegated: Boolean by String::delegated
class Foo {
val member: Boolean by Delegate
val delegated: Boolean by ::member
val String.memberExtension: Boolean by Delegate
val String.memberExtensionDelegated: Boolean by ::member
}
inline fun check(block: () -> Unit) {
@@ -29,16 +33,24 @@ inline fun check(block: () -> Unit) {
fun box(): String {
check { ::topLevel.getDelegate() }
check { ::delegated.getDelegate() }
check { String::extension.getDelegate("") }
check { ""::extension.getDelegate() }
check { String::delegated.getDelegate("") }
check { ""::delegated.getDelegate() }
val foo = Foo()
check { Foo::member.getDelegate(foo) }
check { foo::member.getDelegate() }
check { Foo::delegated.getDelegate(foo) }
check { foo::delegated.getDelegate() }
val me = Foo::class.members.single { it.name == "memberExtension" } as KProperty2<Foo, String, Boolean>
check { me.getDelegate(foo, "") }
val med = Foo::class.members.single { it.name == "memberExtensionDelegated" } as KProperty2<Foo, String, Boolean>
check { med.getDelegate(foo, "") }
return "OK"
}