Skip to content

Commit b16fcb7

Browse files
authored
Merge pull request #9559 from tamasvajk/kotlin-fix-parcelize-symbols-3
Kotlin: substitute fake Parcelize functions with their real equivalent ones
2 parents f737804 + c722921 commit b16fcb7

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
@@ -322,17 +322,17 @@ open class KotlinUsesExtractor(
322322
} ?: c
323323
}
324324

325-
fun tryReplaceAndroidSyntheticFunction(f: IrSimpleFunction): IrSimpleFunction {
325+
private fun tryReplaceFunctionInSyntheticClass(f: IrFunction, getClassReplacement: (IrClass) -> IrClass): IrFunction {
326326
val parentClass = f.parent as? IrClass ?: return f
327-
val replacementClass = tryReplaceAndroidSyntheticClass(parentClass)
327+
val replacementClass = getClassReplacement(parentClass)
328328
if (replacementClass === parentClass)
329329
return f
330330
return globalExtensionState.syntheticToRealFunctionMap.getOrPut(f) {
331331
val result = replacementClass.declarations.find { replacementDecl ->
332-
replacementDecl is IrSimpleFunction && replacementDecl.name == f.name && replacementDecl.valueParameters.zip(f.valueParameters).all {
333-
it.first.type == it.second.type
332+
replacementDecl is IrSimpleFunction && replacementDecl.name == f.name && replacementDecl.valueParameters.size == f.valueParameters.size && replacementDecl.valueParameters.zip(f.valueParameters).all {
333+
erase(it.first.type) == erase(it.second.type)
334334
}
335-
} as IrSimpleFunction?
335+
} as IrFunction?
336336
if (result == null) {
337337
logger.warn("Failed to replace synthetic class function ${f.name}")
338338
} else {
@@ -342,6 +342,11 @@ open class KotlinUsesExtractor(
342342
} ?: f
343343
}
344344

345+
fun tryReplaceSyntheticFunction(f: IrFunction): IrFunction {
346+
val androidReplacement = tryReplaceFunctionInSyntheticClass(f) { tryReplaceAndroidSyntheticClass(it) }
347+
return tryReplaceFunctionInSyntheticClass(androidReplacement) { tryReplaceParcelizeRawType(it)?.first ?: it }
348+
}
349+
345350
fun tryReplaceAndroidSyntheticField(f: IrField): IrField {
346351
val parentClass = f.parent as? IrClass ?: return f
347352
val replacementClass = tryReplaceAndroidSyntheticClass(parentClass)

0 commit comments

Comments
 (0)