Skip to content

Commit 90e225e

Browse files
ShikaSDSpace Cloud
authored andcommitted
Fix compilation of legacy default params on open function
Was broken because integration tests were disabled on prr/ branches. Test: ComposeIT
1 parent 736377f commit 90e225e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

plugins/compose/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3081,7 +3081,7 @@ class ComposableFunctionBodyTransformer(
30813081
// ComposerParamTransformer should not allow for any null arguments on a composable
30823082
// invocation unless the parameter is vararg. If this is null here, we have
30833083
// missed something.
3084-
error("Unexpected null argument for composable call")
3084+
error("Unexpected null argument for composable call: ${expression.dump()}")
30853085
} else {
30863086
argsMeta.add(CallArgumentMeta(isVararg = true))
30873087
continue

plugins/compose/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerParamTransformer.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class ComposerParamTransformer(
427427
if (argIndex < newFn.parameters.size) {
428428
newCall.arguments[argIndex++] = irConst(0)
429429
} else {
430-
error("1. expected value parameter count to be higher: ${this.dumpSrc()}")
430+
error("expected \$сhanged parameter at index $argIndex:\n${newFn.dumpSrc()}")
431431
}
432432
}
433433

@@ -441,7 +441,7 @@ class ComposerParamTransformer(
441441
.sliceArray(start until end)
442442
newCall.arguments[argIndex++] = irConst(bitMask(*bits))
443443
} else if (argumentsMissing.any { it }) {
444-
error("2. expected value parameter count to be higher: ${this.dumpSrc()}")
444+
error("expected \$default parameter at index $argIndex:\n${newFn.dumpSrc()}")
445445
}
446446
}
447447
}
@@ -552,12 +552,24 @@ class ComposerParamTransformer(
552552

553553
private fun IrSimpleFunction.requiresDefaultParameter(): Boolean =
554554
when {
555+
// The function is a default parameter stub generated for backwards compatibility
555556
isDefaultParamStub -> true
557+
// Same as above, but the method was generated by the old compiler, so $default parameter is needed for compatibility
558+
isLegacyOpenFunctionWithDefault() -> true
559+
// Virtual functions move default parameters into a wrapper
556560
isVirtualFunctionWithDefaultParam() -> false
561+
// Fake overrides require default parameters if the original method is not virtual
557562
isFakeOverride -> overriddenSymbols.any { it.owner.modality == Modality.FINAL && it.owner.requiresDefaultParameter() }
563+
// Regular functions also require default parameters
558564
else -> parameters.any { it.defaultValue != null }
559565
}
560566

567+
private fun IrSimpleFunction.isLegacyOpenFunctionWithDefault(): Boolean =
568+
modality == Modality.OPEN && (
569+
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB &&
570+
composeMetadata?.supportsOpenFunctionsWithDefaultParams() != true
571+
) || overriddenSymbols.any { it.owner.isLegacyOpenFunctionWithDefault() }
572+
561573

562574
private fun IrSimpleFunction.hasDefaultForParam(index: Int): Boolean {
563575
// checking for default value isn't enough, you need to ensure that none of the overrides

0 commit comments

Comments
 (0)