Skip to content

Commit c722921

Browse files
committed
Kotlin: substitute fake Parcelize functions with their real equivalent ones
1 parent b0c66dd commit c722921

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class KotlinExtractorGlobalState {
165165
// doesn't have a map as that plugin doesn't generate them. If and when these are used more widely additional maps
166166
// should be added here.
167167
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
168-
val syntheticToRealFunctionMap = HashMap<IrSimpleFunction, IrSimpleFunction?>()
168+
val syntheticToRealFunctionMap = HashMap<IrFunction, IrFunction?>()
169169
val syntheticToRealFieldMap = HashMap<IrField, IrField?>()
170170
}
171171

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ open class KotlinFileExtractor(
15321532

15331533
fun extractCall(c: IrCall, callable: Label<out DbCallable>, stmtExprParent: StmtExprParent) {
15341534
with("call", c) {
1535-
val target = tryReplaceAndroidSyntheticFunction(c.symbol.owner)
1535+
val target = tryReplaceSyntheticFunction(c.symbol.owner)
15361536

15371537
// The vast majority of types of call want an expr context, so make one available lazily:
15381538
val exprParent by lazy {

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,17 @@ open class KotlinUsesExtractor(
378378
} ?: c
379379
}
380380

381-
fun tryReplaceAndroidSyntheticFunction(f: IrSimpleFunction): IrSimpleFunction {
381+
private fun tryReplaceFunctionInSyntheticClass(f: IrFunction, getClassReplacement: (IrClass) -> IrClass): IrFunction {
382382
val parentClass = f.parent as? IrClass ?: return f
383-
val replacementClass = tryReplaceAndroidSyntheticClass(parentClass)
383+
val replacementClass = getClassReplacement(parentClass)
384384
if (replacementClass === parentClass)
385385
return f
386386
return globalExtensionState.syntheticToRealFunctionMap.getOrPut(f) {
387387
val result = replacementClass.declarations.find { replacementDecl ->
388-
replacementDecl is IrSimpleFunction && replacementDecl.name == f.name && replacementDecl.valueParameters.zip(f.valueParameters).all {
389-
it.first.type == it.second.type
388+
replacementDecl is IrSimpleFunction && replacementDecl.name == f.name && replacementDecl.valueParameters.size == f.valueParameters.size && replacementDecl.valueParameters.zip(f.valueParameters).all {
389+
erase(it.first.type) == erase(it.second.type)
390390
}
391-
} as IrSimpleFunction?
391+
} as IrFunction?
392392
if (result == null) {
393393
logger.warn("Failed to replace synthetic class function ${f.name}")
394394
} else {
@@ -398,6 +398,11 @@ open class KotlinUsesExtractor(
398398
} ?: f
399399
}
400400

401+
fun tryReplaceSyntheticFunction(f: IrFunction): IrFunction {
402+
val androidReplacement = tryReplaceFunctionInSyntheticClass(f) { tryReplaceAndroidSyntheticClass(it) }
403+
return tryReplaceFunctionInSyntheticClass(androidReplacement) { tryReplaceParcelizeRawType(it)?.first ?: it }
404+
}
405+
401406
fun tryReplaceAndroidSyntheticField(f: IrField): IrField {
402407
val parentClass = f.parent as? IrClass ?: return f
403408
val replacementClass = tryReplaceAndroidSyntheticClass(parentClass)

0 commit comments

Comments
 (0)