Files
kotlin-fork/compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt
T
Mads Ager c922484758 [JVM_IR] Use direct field access to backing fields on current class.
The current backend uses direct field access to the backing field
instead of calling the companion object accessor, which calls
an accessibility bridge, which then gets the field for code such as:

```
class A {
  companion object {
    val s: String = "OK"
  }

  // f uses direct access to the A.s backing field.
  fun f() = s
}
```

This change does the same for the IR backend.
2020-12-11 06:24:55 +01:00

23 lines
475 B
Kotlin
Vendored

class A {
companion object {
val s: String
get() = "Ok"
var v : String
get() = "NOT OK"
set(value) {}
}
inline fun f(): String = s
inline fun g() {
v = "OK"
}
}
// No backing field on A and all accesses call the getter/setter.
// 0 GETSTATIC A.s
// 0 PUTSTATIC A.v
// One `getS` call in `f` and one `setV` call in `g`
// 1 INVOKEVIRTUAL A\$Companion.getS
// 1 INVOKEVIRTUAL A\$Companion.setV