Added INSTANCE_INITIALIZER_CALL to enum classes.
Initializers lowering relies on fact that each constructor calling super constructor has also INSTANCE_INITIALIZER_CALL in it's body.
This commit is contained in:
+23
@@ -126,6 +126,7 @@ internal class EnumClassLowering(val context: Context) : ClassLoweringPass {
|
||||
private lateinit var valueOfFunctionDescriptor: FunctionDescriptor
|
||||
|
||||
fun run() {
|
||||
insertInstanceInitializerCall()
|
||||
assignOrdinalsToEnumEntries()
|
||||
lowerEnumConstructors(irClass)
|
||||
lowerEnumEntriesClasses()
|
||||
@@ -136,6 +137,28 @@ internal class EnumClassLowering(val context: Context) : ClassLoweringPass {
|
||||
createImplObject()
|
||||
}
|
||||
|
||||
private fun insertInstanceInitializerCall() {
|
||||
irClass.transformChildrenVoid(object: IrElementTransformerVoid() {
|
||||
override fun visitClass(declaration: IrClass): IrStatement {
|
||||
// Skip nested
|
||||
return declaration
|
||||
}
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor): IrStatement {
|
||||
declaration.transformChildrenVoid(this)
|
||||
|
||||
val blockBody = declaration.body as? IrBlockBody ?: throw AssertionError("Unexpected constructor body: ${declaration.body}")
|
||||
blockBody.statements.transformFlat {
|
||||
if (it is IrEnumConstructorCall)
|
||||
listOf(it, IrInstanceInitializerCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
irClass.descriptor))
|
||||
else null
|
||||
}
|
||||
return declaration
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun assignOrdinalsToEnumEntries() {
|
||||
var ordinal = 0
|
||||
irClass.declarations.forEach {
|
||||
|
||||
Reference in New Issue
Block a user