JVM IR: Optimize field initializers in secondary constructors

This commit is contained in:
Steven Schäfer
2020-04-23 11:55:29 +02:00
committed by max-kammerer
parent fed6272de4
commit cb3a4727cf
8 changed files with 51 additions and 2 deletions
@@ -0,0 +1,20 @@
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: JS_IR
open class Base {
open fun setup() {}
init { setup() }
}
class Derived : Base {
constructor() : super()
override fun setup() { x = 1 }
// Technically, this field initializer comes after the superclass
// constructor is called. However, we optimize away field initializers
// which set fields to their default value, which is why x ends up with
// value 1 after the constructor call.
var x = 0
}
fun box(): String = if (Derived().x == 1) "OK" else "Fail"