[JS_IR] Invoke companion init block while instantiating a class

KT-40740, squashed rr/shagen/KT-40740-static-init-js-ir
This commit is contained in:
Shagen Ogandzhanian
2020-10-30 16:15:15 +01:00
parent 22117604f6
commit 2d0535a713
4 changed files with 58 additions and 9 deletions
@@ -1,22 +1,28 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS_IR_ES6
var global = 0;
var global = "A"
class C {
init {
global += "D"
}
companion object {
init {
global = 1;
global += "B"
}
init {
global += "C"
}
}
}
fun box(): String {
if (global != 0) {
if (global != "A") {
return "fail1: global = $global"
}
val c = C()
if (global == 1) return "OK" else return "fail2: global = $global"
if (global == "ABCD") return "OK" else return "fail2: global = $global"
}