touchlab / SKIE

SKIE - Swift Kotlin Interface Enhancer
https://skie.touchlab.co/
Apache License 2.0
751 stars 8 forks source link

Generics in sealed interfaces #108

Closed shlauzer closed 2 months ago

shlauzer commented 2 months ago

According to the article https://touchlab.co/sealed-generics-and-skie, I expected that sealed interfaces with generics will have a parametrized equivalent type in Swift code, but it doesn't. For example:

sealed interface LceInitialState<out T : Any, out E : Any?> {

    data object Loading : LceInitialState<Nothing, Nothing>

    data class Content<out T : Any>(val data: T) : LceInitialState<T, Nothing>

    data class Error<out E : Any?>(val error: E) : LceInitialState<Nothing, E>
}

In this case, I get a compile error in XCode when I define the type LceInitialState<State, KotlinUnit>). But if I replace interface with class, it starts working.

My SKIE version is 0.8.4.

FilipDolnik commented 2 months ago

Hi! Interfaces lose generics in Swift due to interop limitations, so this is expected behavior.

I agree that the wording of the article's last sentence can be slightly confusing, so I changed it. (The intent was to say that sealed interfaces are supported as well, not that they support generics.)