I’m seeing an error relating to `kotlin.Result` wh...
# jvm-ir-backend-feedback
r
I’m seeing an error relating to
kotlin.Result
when I enable IR. No other changes. [This line of code](https://github.com/robfletcher/strikt/blob/main/strikt-core/src/main/kotlin/strikt/assertions/Result.kt#L17) starts throwing
Copy code
java.lang.ClassCastException: class kotlin.Result$Failure cannot be cast to class kotlin.Result (kotlin.Result$Failure and kotlin.Result are in unnamed module of loader 'app')
However, it’s only doing it in one context which is very confusing
i
I minimized your code.
Copy code
import kotlinx.coroutines.runBlocking

fun <R> Builder<Result<R>>.isFailure(): Builder<Throwable> =
    this.get { exceptionOrNull()!! }

interface Builder<T> {
    fun <R> get(
        function: T.() -> R
    ): Builder<R>
}

inline fun <reified E : Throwable> expectThrows(
    noinline action: () -> Any?
): Builder<E> =
    AssertionBuilder(
        AssertionSubject(
            try {
                runBlocking { action() }.let(Result.Companion::success)
            } catch (e: Throwable) {
                Result.failure(e)
            }
        )
    ).failedWith()


@Suppress("UNCHECKED_CAST")
inline fun <reified E : Throwable> Builder<Result<*>>.failedWith() =
    isFailure() as Builder<E>

fun main() {
    expectThrows<IllegalStateException> { error("o noes") }
}

class AssertionSubject<S>(
    val subject: S
)

class AssertionBuilder<T>(
    private val context: AssertionSubject<T>
) : Builder<T> {

    override fun <R> get(
        function: (T) -> R
    ): Builder<R> = runCatching {
        function(context.subject)
    }
        .getOrElse { ex -> throw RuntimeException("", ex) }
        .let {
            TODO()
        }
}
Looks like the problem was fixed in https://youtrack.jetbrains.com/issue/KT-44671
r
oh nice, thank you
410 Views