mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-11 15:53:46 +00:00
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
32 lines
649 B
Kotlin
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"
|
|
}
|