Files
kotlin/compiler/testData/codegen/box/objects/interfaceCompanion.kt
pyos 939a9ff53e JVM_IR: fix NPE in interface companion initializers
* When referencing the companion itself, they should use the $$INSTANCE
  field, not the (null until <clinit> returns) Companion field of the
  interface.

* Interface companion init blocks should be made static.
2019-11-20 14:37:19 +01:00

23 lines
521 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// Inside of the companion we have to access the instance through the local Companion field,
// not by indirection through the Companion field of the enclosing class.
// Class initialization might not have finished yet.
var result = ""
interface A {
companion object {
val prop = test()
fun test(): String {
result += "OK"
return result
}
}
}
fun box(): String {
if (A.prop != "OK") return "fail ${A.prop}"
return result
}