Files
kotlin-fork/compiler/testData/codegen/box/properties/const/constFlags.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

52 lines
1.3 KiB
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_STDLIB
// FULL_JDK
@file:JvmName("XYZ")
import java.lang.reflect.Modifier
private const val privateConst: Int = 1
public const val publicConst: Int = 3
public object A {
private const val privateConst: Int = 1
public const val publicConst: Int = 3
}
public class B {
companion object {
private const val privateConst: Int = 1
protected const val protectedConst: Int = 2
public const val publicConst: Int = 3
}
}
fun check(clazz: Class<*>, expectProtected: Boolean = true) {
val fields = clazz.declaredFields.filter { it.name.contains("Const") }
assert(fields.all { Modifier.isStatic(it.modifiers) }) { "`$clazz` contains non-static fields" }
assert(Modifier.isPrivate(fields.single { it.name.contains("private") }.modifiers)) {
"`$clazz`.privateConst is not private"
}
assert(Modifier.isPublic(fields.single { it.name.contains("public") }.modifiers)) {
"`$clazz`.publicConst is not public"
}
if (expectProtected) {
assert(Modifier.isProtected(fields.single { it.name.contains("protected") }.modifiers)) {
"`$clazz`.protectedConst is not protected"
}
}
}
fun box(): String {
check(A::class.java, false)
check(B::class.java)
check(Class.forName("XYZ"), false)
return "OK"
}