Files
kotlin/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.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

30 lines
646 B
Kotlin

import kotlin.reflect.IllegalAccessException
import kotlin.reflect.KMemberProperty
import kotlin.reflect.jvm.accessible
class Result {
private val value = "OK"
fun ref(): KMemberProperty<Result, String> = ::value
}
fun box(): String {
val p = Result().ref()
try {
p.get(Result())
return "Fail: private property is accessible by default"
} catch(e: IllegalAccessException) { }
p.accessible = true
val r = p.get(Result())
p.accessible = false
try {
p.get(Result())
return "Fail: setAccessible(false) had no effect"
} catch(e: IllegalAccessException) { }
return r
}