Skip to content

Commit 30d7f0c

Browse files
authored
Merge pull request github#14334 from igfoo/igfoo/ext-frag
Kotlin: Handle IrExternalPackageFragment properly for more external entities
2 parents 7f5f25c + 5db283e commit 30d7f0c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,23 @@ open class KotlinUsesExtractor(
298298
}
299299
}
300300

301+
private fun extractParentExternalClassLater(d: IrDeclaration) {
302+
val p = d.parent
303+
when (p) {
304+
is IrClass -> extractExternalClassLater(p)
305+
is IrExternalPackageFragment -> {
306+
// The parent is a (multi)file class. We don't need to
307+
// extract it separately.
308+
}
309+
else -> {
310+
logger.warn("Unexpected parent type ${p.javaClass} for external file class member")
311+
}
312+
}
313+
}
314+
301315
private fun extractPropertyLaterIfExternalFileMember(p: IrProperty) {
302316
if (isExternalFileClassMember(p)) {
303-
extractExternalClassLater(p.parentAsClass)
317+
extractParentExternalClassLater(p)
304318
val signature = getTrapFileSignature(p)
305319
dependencyCollector?.addDependency(p, signature)
306320
externalClassExtractor.extractLater(p, signature)
@@ -309,7 +323,7 @@ open class KotlinUsesExtractor(
309323

310324
private fun extractFieldLaterIfExternalFileMember(f: IrField) {
311325
if (isExternalFileClassMember(f)) {
312-
extractExternalClassLater(f.parentAsClass)
326+
extractParentExternalClassLater(f)
313327
val signature = getTrapFileSignature(f)
314328
dependencyCollector?.addDependency(f, signature)
315329
externalClassExtractor.extractLater(f, signature)
@@ -318,17 +332,7 @@ open class KotlinUsesExtractor(
318332

319333
private fun extractFunctionLaterIfExternalFileMember(f: IrFunction) {
320334
if (isExternalFileClassMember(f)) {
321-
val p = f.parent
322-
when (p) {
323-
is IrClass -> extractExternalClassLater(p)
324-
is IrExternalPackageFragment -> {
325-
// The parent is a (multi)file class. We don't need
326-
// extract it separately.
327-
}
328-
else -> {
329-
logger.warn("Unexpected parent type ${p.javaClass} for external file class member")
330-
}
331-
}
335+
extractParentExternalClassLater(f)
332336
(f as? IrSimpleFunction)?.correspondingPropertySymbol?.let {
333337
extractPropertyLaterIfExternalFileMember(it.owner)
334338
// No need to extract the function specifically, as the property's

0 commit comments

Comments
 (0)