JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.36k stars 1.18k forks source link

Compose Compiler (iOS): public Composable functions in expect/actual class is attempted to be exported to ObjC #4848

Closed eymar closed 2 months ago

eymar commented 6 months ago

When updating the jetsnack example to Kotlin 2, the iOS target won't compile:

e: Compilation failed: no implementation for FUN MISSING_DECLARATION name:shouldShowBottomBar visibility:public modality:FINAL <> () returnType:kotlin.Nothing

Affected platforms

Versions

To Reproduce

expect abstract class JetSnackCartViewModel() {
    @Composable
    fun collectOrderLinesAsState(flow: StateFlow<List<OrderLine>>): State<List<OrderLine>>
}

// Then an actual
actual abstract class JetSnackCartViewModel actual constructor()  {
    @Composable
    actual fun collectOrderLinesAsState(flow: StateFlow<List<OrderLine>>): State<List<OrderLine>> {
        return flow.collectAsState()
    }
}

The workaround is to add:

@OptIn(kotlin.experimental.ExperimentalObjCRefinement::class)
@HiddenFromObjC

on the actual class., or make the class internal.

eymar commented 6 months ago

Marking it as a regression, because there is no issue when using kotlin 1.9.2x My guess is that the issue could be on Kotlin side, but only an investigation can confirm.


Another possible reason: Maybe we skip 'expect' classes/functions in our lowering AddHiddenFromObjC. And k/native relies on them to create the exports in 2.0?

okushnikov commented 3 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.