Skip to main content

Lambda type as a type argument is not supported in generated Swift code

SKIE cannot currently generate Swift code that contains types with lambdas used as a type argument for generic Kotlin classes.

For example, the following code would not compile because it generates a Swift enum class that contains a function with the problematic signature:

Kotlin
class A<T>

enum class E {
Q;

fun foo(): A<() -> Unit> = A()
}

In the above case, you would receive the following error message:

error: 'A' requires that '() -> __Skie.class__stdlib__kotlin_Unit' (aka '() -> KotlinUnit') be a class type
public func foo() -> __Skie.class__A<() -> __Skie.class__stdlib__kotlin_Unit> {

As a workaround, SKIE replaces the lambda type with a special type __SkieLambdaErrorType and marks it as @available(*, unavailable) in the generated Swift code. This way, the code compiles, and you can use everything but declarations with the special type.

This issue is fundamentally caused by a bug/limitation in the Swift compiler, but we are investigating possible workarounds that would allow calling the problematic declarations.

note

All other types can be used as type arguments. For example, changing the function signature to fun foo(): A<Unit> works as expected. It's only the lambda types that are causing this problem.