Skip to content

Commit

Permalink
fix: overloaded fun + default args transformation (#1066)
Browse files Browse the repository at this point in the history
JetBrains/compose-multiplatform#3318

fix default value propagation for overridden composable functions
parameter with default value should be transformed to nullable type
(what didn't happen for overridden functions)
JVM/JS targets was not affected by that issue because all types are
already nullable, which is not true for K/Native
  • Loading branch information
shishkin-pavel authored and eymar committed Feb 14, 2024
1 parent db2b45f commit 05316ee
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class ComposerParamTransformer(

fn.dispatchReceiverParameter = dispatchReceiverParameter?.copyTo(fn)
fn.extensionReceiverParameter = extensionReceiverParameter?.copyTo(fn)
fn.valueParameters = valueParameters.map { param ->
fn.valueParameters = valueParameters.mapIndexed { i, param ->
// Composable lambdas will always have `IrGet`s of all of their parameters
// generated, since they are passed into the restart lambda. This causes an
// interesting corner case with "anonymous parameters" of composable functions.
Expand All @@ -422,7 +422,8 @@ class ComposerParamTransformer(
// the names here to ensure that dex is always safe.
val newName = dexSafeName(param.name)

val newType = defaultParameterType(param).remapTypeParameters()
val isDefaultInOverriden = overriddenSymbols.any { it.owner.hasDefaultExpressionDefinedForValueParameter(i) }
val newType = defaultParameterType(param, isDefaultInOverriden).remapTypeParameters()
param.copyTo(
fn,
name = newName,
Expand Down Expand Up @@ -615,9 +616,10 @@ class ComposerParamTransformer(
}
}

private fun defaultParameterType(param: IrValueParameter): IrType {
private fun defaultParameterType(param: IrValueParameter, isDefaultInOverriden: Boolean): IrType {
val type = param.type
if (param.defaultValue == null) return type

if (!isDefaultInOverriden && param.defaultValue == null) return type
val constructorAccessible = !type.isPrimitiveType() &&
type.classOrNull?.owner?.primaryConstructor != null
return when {
Expand Down

0 comments on commit 05316ee

Please sign in to comment.