Files
kotlin-fork/compiler/testData/codegen/box/jvmField/classFieldReference.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

47 lines
1.2 KiB
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_STDLIB
package zzz
import java.lang.reflect.Field
import kotlin.reflect.KProperty1
import kotlin.reflect.KProperty0
import kotlin.test.assertEquals
class A(val s1: String, val s2: String) {
@JvmField public val publicField = s1;
@JvmField internal val internalField = s2;
fun testAccessors() {
checkAccessor(A::publicField, s1, this)
checkAccessor(A::internalField, s2, this)
}
}
class AWithCompanion {
companion object {
@JvmField public val publicField = "1";
@JvmField internal val internalField = "2";
fun testAccessors() {
checkAccessor(AWithCompanion.Companion::publicField, "1")
checkAccessor(AWithCompanion.Companion::internalField, "2")
}
}
}
fun box(): String {
A("1", "2").testAccessors()
AWithCompanion.testAccessors()
return "OK"
}
public fun <T, R> checkAccessor(prop: KProperty1<T, R>, value: R, receiver: T) {
assertEquals(prop.get(receiver), value, "Property ${prop} has wrong value")
}
public fun <R> checkAccessor(prop: KProperty0<R>, value: R) {
assertEquals(prop.get(), value, "Property ${prop} has wrong value")
}