touchlab / SKIE

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

Flow interop does not preserve default types Boolean/Int #61

Closed suau closed 9 months ago

suau commented 9 months ago

What is the problem?

How do we reproduce the issue?

Here the dummy greetings project from an otherwise empty project.

import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.update

class Greeting {
    private val platform: Platform = getPlatform()
    private val _messages = MutableStateFlow(emptyList<String>())
    val messages: StateFlow<List<String>> = _messages
    val intFlow = MutableStateFlow(1)
    val boolFlow = MutableStateFlow<Boolean>(true)
    val boolFlow2: StateFlow<Boolean> = boolFlow
    val boolListFlow = MutableStateFlow(emptyList<Boolean>())
    val optionalBoolFlow = MutableStateFlow<Boolean?>(null)
    var boolNormal = true
    var boolFlow3: Flow<Boolean> = flow {
        for (i in 1..3) {
            delay(100) // pretend we are doing something useful here
            emit(i % 2 == 0) // emit next value
        }
    }

    fun greet(): String {
        return "Hello, ${platform.name}!"
    }

    suspend fun repeat(message: String): String {
        delay(1000)
        _messages.update {
            it + message
        }
        return "message was: $message"
    }
}

What versions of SKIE, Kotlin, and Gradle do you use?

Kotlin: 1.9.22 SKIE: 0.6.1

What is your SKIE Gradle configuration?

no additional config in Gradle

TadeasKriz commented 9 months ago

Thank you for the report. It's a little inaccurate. SkieSwiftXXXFlow types are expected, but what you probably meant was that the element types supplied are KotlinInt, KotlinBoolean etc. This is caused by how Kotlin handles these types currently with generics and closures.

We should be able to fix this, but it'd be a source-breaking change for the rest of the codebase, because it'd map all KotlinInt to Int32, KotlinBoolean to Bool etc. I'll go ahead and convert this issue into a discussion so we can keep track of it as a proposed feature.