JVM_IR: Support init blocks in inline classes

Put their content to constructor-impl, so they are called during
constructor call, but they are not called during boxing, because
box-impl calls <init> and not constructor-impl.

 #KT-28055 In progress
This commit is contained in:
Ilmir Usmanov
2020-10-28 01:46:38 +01:00
parent 5804f73ebd
commit 999604541e
15 changed files with 323 additions and 24 deletions
@@ -0,0 +1,24 @@
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND: JS_IR
// IGNORE_LIGHT_ANALYSIS
inline class IC(val i: Int) {
init {
counter += i
}
}
var counter = 0
fun <T> id(t: T) = t
fun box(): String {
val ic = IC(42)
if (counter != 42) return "FAIL 1: $counter"
counter = 0
id(ic)
if (counter != 0) return "FAIL 2: $counter"
return "OK"
}