Files
kotlin/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt
Alexander Udalov 36f7cc742f Introduce NoSuchPropertyException and IllegalAccessException
No new tests added because it's difficult to model a situation where a
::-access is allowed but the code throws these exceptions at runtime
2014-07-02 01:58:22 +04:00

32 lines
649 B
Kotlin

import kotlin.reflect.IllegalAccessException
import kotlin.reflect.KMutableMemberProperty
import kotlin.reflect.jvm.accessible
class A {
private var value = 0
fun ref(): KMutableMemberProperty<A, Int> = ::value
}
fun box(): String {
val a = A()
val p = a.ref()
try {
p.set(a, 1)
return "Fail: private property is accessible by default"
} catch(e: IllegalAccessException) { }
p.accessible = true
p.set(a, 2)
p.get(a)
p.accessible = false
try {
p.set(a, 3)
return "Fail: setAccessible(false) had no effect"
} catch(e: IllegalAccessException) { }
return "OK"
}