[K/N] Extract const val initializers to place of usage

This would make behaviour more consistent with jvm. There is still
a difference in behaviour about point where side effects happen.

^KT-52970
This commit is contained in:
Pavel Kunyavskiy
2022-07-11 16:39:13 +02:00
committed by Space
parent 6a8da8f9eb
commit 5cdda48487
15 changed files with 212 additions and 43 deletions
@@ -0,0 +1,22 @@
// MODULE: lib1
// FILE: lib1.kt
object L1 {
lateinit var block: () -> Unit
}
// MODULE: lib2(lib1)
// FILE: lib2.kt
object L2 {
val sideEffect = L1.block()
const val x = 42
fun triggerInitialization() {}
}
// MODULE: main(lib1, lib2)
// FILE: main.kt
fun box(): String {
var result = 0
L1.block = { result = L2.x }
L2.triggerInitialization()
if (result != 42) return "FAIL: $result"
return "OK"
}