Thread
#multiplatform
    Jess Brent

    Jess Brent

    2 years ago
    not sure if this is the right place, i’m a little baffled trying to make this work and i can’t seem to find anything on google to answer my questions. function:
    inline fun <reified T> withResult(
        method: Result<T>,
        onFailure: (errors: List<Throwable>) -> Unit
    ): T {
            @Suppress("IMPLICIT_CAST_TO_ANY")
            val methodResult = when (method) {
                is Result.Success -> { method.t }
                is Result.Failure -> { onFailure.invoke(method.errors) }
            }
            return methodResult as T
    }
    usage:
    val r = withResult(method) { return Result.Failure(it) }
    i can get this function to work on jvm, however it does not work on js. it results in a
    ClassCastException
    the transpiled js appears to show that instead of invoking
    onFailure
    it is only assigned to
    methodResult
    . also, this is a custom sealed class
    Result
    not
    kotlin.Result
    i’m hoping i’m missing something obvious here. 😅
    bug here: https://youtrack.jetbrains.com/issue/KT-24680 tl;dr drop
    invoke()
    and it works