Files
kotlin-fork/compiler/testData/codegen/box/javaFieldAndKotlinProperty/javaFieldAndCompanionProperty.kt
T
Alexander Udalov 4ad594a3cd Minor, move tests about Java field and Kotlin property
Because the `fieldRename` directory was originally about cases when
private fields are renamed because of clashes.
2023-02-23 12:54:00 +01:00

38 lines
786 B
Kotlin
Vendored

// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// FIR_STATUS: accesses companion property backing field statically and fails (does not work in K1/JVM too)
// FILE: Base.java
public class Base {
protected String TAG = "OK";
public String foo() {
return TAG;
}
}
// FILE: Sub.kt
class Sub : Base() {
companion object {
val TAG = "FAIL"
}
fun log() = TAG
fun logReference() = this::TAG.get()
fun logAssignment(): String {
TAG = "12"
if (foo() != "12") return "Error writing: ${foo()}"
return "OK"
}
}
fun box(): String {
if (Sub().log() != "OK") return Sub().log()
if (Sub().logReference() != "OK") return Sub().logReference()
return Sub().logAssignment()
}