Going from 1.9.22 to beta4, I've had a few runtime...
# k2-adopters
s
Going from 1.9.22 to beta4, I've had a few runtime failures. I've boiled an example down to this test case:
Copy code
class FunInterfaceTest  {
    fun interface FunInterface {
        suspend operator fun invoke() // <- suspend
    }
    fun func(f: FunInterface) = Unit

    @Test
    fun `this fails on k2`() {
        val lambda: () -> Unit = { } // <- no suspend
        func(f = lambda)
    }

    @Test
    fun `this always works`() {
        val lambda: suspend () -> Unit = { } // <- suspend
        func(f = lambda)
    }
}
With this first test throwing the following runtime error:
Copy code
java.lang.ClassCastException: class <class>$lambda$1 cannot be cast to class kotlin.jvm.functions.Function1 (<class>$lambda$1 and kotlin.jvm.functions.Function1 are in unnamed module of loader 'app')
In short: I'm calling a function
f
that expects a
FunInterface
. The fun interface's function is suspending. On 1.9.22, I can use a lambda of type
() -> Unit
or of type
suspend () -> Unit
to call
f
. On K2 beta 4, I can only use a lambda of type
suspend () -> Unit
to call
f
. I have a sneaking suspicion that using the non-suspend variant on 1.9.22 worked just by coincidence, and that I've been doing something that isn't actually allowed by the language. Still, it's a change of behavior compared to 1.9. And I would have assumed that the compile-time type checking should throw an error during compilation if this were disallowed. Is this worth reporting?
m
Yes, it's better to report it
s
k
It looks like a real bug. We'll fix it for the next beta.
🙌 1