Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e24d78a

Browse files
smowtonigfoo
authored andcommitted
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.
1 parent 9fd9894 commit e24d78a

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,14 @@ open class KotlinFileExtractor(
522522
return
523523
}
524524

525-
extractDeclInitializers(enclosingClass.declarations, false) {
526-
Pair(tw.getFreshIdLabel<DbBlock>().also({
527-
tw.writeStmts_block(it, parent.parent, parent.idx, constructorId)
528-
val locId = tw.getLocation(enclosingConstructor)
529-
tw.writeHasLocation(it, locId)
530-
}), constructorId)
531-
}
525+
// Don't make this block lazily since we need to insert something at the given parent.idx position,
526+
// and in the case where there are no initializers to emit an empty block is an acceptable filler.
527+
val initBlockId = tw.getFreshIdLabel<DbBlock>().also {
528+
tw.writeStmts_block(it, parent.parent, parent.idx, constructorId)
529+
val locId = tw.getLocation(enclosingConstructor)
530+
tw.writeHasLocation(it, locId)
531+
}
532+
extractDeclInitializers(enclosingClass.declarations, false) { Pair(initBlockId, constructorId) }
532533
}
533534
}
534535

0 commit comments

Comments
 (0)