Hello, I am trying to move our codebase to kotlin ...
# multiplatform
m
Hello, I am trying to move our codebase to kotlin 2 and I have failed in this particular case, which does not let me compile (specifically on iOS).
Copy code
expect sealed class FeatureDestination {
    abstract class NoArgs : FeatureDestination
    sealed class WithArgs<T> : FeatureDestination
}
on all platforms, there are actual implementations with different members. Part of iOS is like this:
Copy code
actual sealed class FeatureDestination(val route: Route) {

    abstract val viewModel: FeatureBoundInstance

    actual sealed class WithArgs<T>(route: Route, open val arguments: T) : FeatureDestination(route) {
        ...
    }
}

fun interface FeatureBoundInstance {
    fun clear()
}
Then, I will try to inherit from this, again with expect actual combo, and iOS part looks like this:
Copy code
actual class BillingInfoDestination(billingInfo: BillingInfo) : FeatureDestination.WithArgs<BillingInfo>(
    route = Route(),
    arguments = billingInfo
) {
    override val viewModel: BillingInfoViewModel by lazy { KoinPlatformTools.defaultContext().get().get() }
 
    ...
}
This will not compile, with the following error, even though BillingInfoViewModel does inherit from interface FeatureBoundInstance.
Copy code
error: 'val viewModel: BillingInfoViewModel' has no corresponding expected declaration
The following declaration is incompatible because return type is different:
    val viewModel: FeatureBoundInstance
What is wrong with this code in K2? I get that it's more strict, but why would I need something in common with expect when it is needed only in one platform? Thank you for help and/or answers!