slackhq / circuit

⚡️ A Compose-driven architecture for Kotlin and Android applications.
https://slackhq.github.io/circuit/
Apache License 2.0
1.51k stars 76 forks source link

StaticScreen codegen broken for kotlinInject/kotlinInjectAnvil #1704

Open wiyarmir opened 1 month ago

wiyarmir commented 1 month ago

Having a screen such as

@Parcelize
data object Static : StaticScreen

@CircuitInject(Static::class, AppScope::class)
@Composable
fun StaticUi(screen: Static, modifier: Modifier) {} 

generates

@Inject
@ContributesBinding(
  AppScope::class,
  multibinding = true,
)
public class StaticUiFactory : Ui.Factory {
  override fun create(screen: Screen, context: CircuitContext): Ui<*>? = when (screen) {
    Static -> ui<CircuitUiState> { _, modifier -> StaticUi(modifier = modifier, screen) }
    else -> null
  }
}

which is invalid because it mixes named and positional arguments

setup: no multiplatform, single module

kotlinInject = "0.7.2"
kotlinInjectAnvil = "0.0.4"
circuit = "0.24.0"
wiyarmir commented 1 month ago

I've tried quickly adding Screen to the known parameters in the FactoryType.UI case in computeFactoryData() but I didn't understand the impact of modifying KSFunctionDeclaration.assistedParameters(...) so it doesn't generate it twice

ZacSweers commented 1 month ago

I think we should make this not generate invalid code, but out of curiosity - why do you need the object passed as a param given its singleton nature?

wiyarmir commented 1 month ago

I was trying to make the simplest reproduction but with a data class it also fails (but correctly uses a is in the when case)

On Tue, 8 Oct 2024, 03:03 Zac Sweers, @.***> wrote:

I think we should make this not generate invalid code, but out of curiosity - why do you need the object passed as a param given its singleton nature?

— Reply to this email directly, view it on GitHub https://github.com/slackhq/circuit/issues/1704#issuecomment-2398493647, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABKANAPDRFADRAUAPNCGP3Z2M4OHAVCNFSM6AAAAABPLXJMMOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJYGQ4TGNRUG4 . You are receiving this because you authored the thread.Message ID: @.***>