Michal Lepíček
06/05/2024, 3:23 PMexpect 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:
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:
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.
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!