Type-check reference to property with invisible setter to KProperty

#KT-12337 Fixed
This commit is contained in:
Alexander Udalov
2016-06-15 17:53:52 +03:00
parent c5a208f3eb
commit 6562a2db19
13 changed files with 145 additions and 19 deletions
@@ -0,0 +1,34 @@
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.reflect.jvm.*
object Delegate {
operator fun getValue(thiz: My, property: KProperty<*>): String {
if (property !is KMutableProperty<*>) return "Fail: property is not a KMutableProperty"
property as KMutableProperty1<My, String>
try {
property.set(thiz, "")
return "Fail: property.set should cause IllegalCallableAccessException"
}
catch (e: IllegalCallableAccessException) {
// OK
}
property.accessible = true
property.set(thiz, "")
return "OK"
}
operator fun setValue(thiz: My, property: KProperty<*>, value: String) {
}
}
class My {
var delegate: String by Delegate
private set
}
fun box() = My().delegate