@@ -83,7 +83,7 @@ open class KotlinFileExtractor(
83
83
}
84
84
85
85
file.declarations.forEach { extractDeclaration(it, extractPrivateMembers = true , extractFunctionBodies = true ) }
86
- extractStaticInitializer(file, null )
86
+ extractStaticInitializer(file, { extractFileClass(file) } )
87
87
CommentExtractor (this , file, tw.fileId).extract()
88
88
}
89
89
}
@@ -423,7 +423,7 @@ open class KotlinFileExtractor(
423
423
if (extractDeclarations) {
424
424
c.declarations.forEach { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies) }
425
425
if (extractStaticInitializer)
426
- extractStaticInitializer(c, id )
426
+ extractStaticInitializer(c, { id } )
427
427
extractJvmStaticProxyMethods(c, id, extractPrivateMembers, extractFunctionBodies)
428
428
}
429
429
if (c.isNonCompanionObject) {
@@ -638,13 +638,18 @@ open class KotlinFileExtractor(
638
638
return type
639
639
}
640
640
641
- private fun extractStaticInitializer (container : IrDeclarationContainer , classLabel : Label <out DbClassorinterface >? ) {
641
+ /* *
642
+ * mkContainerLabel is a lambda so that we get laziness: If the
643
+ * container is a file, then we don't want to extract the file class
644
+ * unless something actually needs it.
645
+ */
646
+ private fun extractStaticInitializer (container : IrDeclarationContainer , mkContainerLabel : () -> Label <out DbClassorinterface >) {
642
647
with (" static initializer extraction" , container) {
643
648
extractDeclInitializers(container.declarations, true ) {
644
- val parentId = classLabel ? : extractFileClass(container as IrFile )
649
+ val containerId = mkContainerLabel( )
645
650
val clinitLabel = getFunctionLabel(
646
651
container,
647
- parentId ,
652
+ containerId ,
648
653
" <clinit>" ,
649
654
listOf (),
650
655
pluginContext.irBuiltIns.unitType,
@@ -657,7 +662,7 @@ open class KotlinFileExtractor(
657
662
)
658
663
val clinitId = tw.getLabelFor<DbMethod >(clinitLabel)
659
664
val returnType = useType(pluginContext.irBuiltIns.unitType, TypeContext .RETURN )
660
- tw.writeMethods(clinitId, " <clinit>" , " <clinit>()" , returnType.javaResult.id, parentId , clinitId)
665
+ tw.writeMethods(clinitId, " <clinit>" , " <clinit>()" , returnType.javaResult.id, containerId , clinitId)
661
666
tw.writeMethodsKotlinType(clinitId, returnType.kotlinResult.id)
662
667
663
668
tw.writeCompiler_generated(clinitId, CompilerGeneratedKinds .CLASS_INITIALISATION_METHOD .kind)
0 commit comments