Create instance variable initializer block eagerly

Otherwise when the init block is followed by other constructor statements we can get a gap in a BasicBlock's child sequence due to the child init block never getting created at all.
This commit is contained in:
Chris Smowton
2022-03-16 17:51:31 +00:00
committed by Ian Lynagh
parent 9fd9894f6a
commit e24d78ae14

View File

@@ -522,13 +522,14 @@ open class KotlinFileExtractor(
return
}
extractDeclInitializers(enclosingClass.declarations, false) {
Pair(tw.getFreshIdLabel<DbBlock>().also({
tw.writeStmts_block(it, parent.parent, parent.idx, constructorId)
val locId = tw.getLocation(enclosingConstructor)
tw.writeHasLocation(it, locId)
}), constructorId)
// Don't make this block lazily since we need to insert something at the given parent.idx position,
// and in the case where there are no initializers to emit an empty block is an acceptable filler.
val initBlockId = tw.getFreshIdLabel<DbBlock>().also {
tw.writeStmts_block(it, parent.parent, parent.idx, constructorId)
val locId = tw.getLocation(enclosingConstructor)
tw.writeHasLocation(it, locId)
}
extractDeclInitializers(enclosingClass.declarations, false) { Pair(initBlockId, constructorId) }
}
}