Norbi
02/04/2023, 12:30 PM4
to the console:
@Test
fun testBug() {
runBlocking {
println(f(2) { this() })
}
}
suspend fun <T> f(value: Int, block: context(A) Int.() -> T): T = block(A(), value)
class A {
operator fun Int.invoke() = this * 2
}
But making all functions suspend results in a runtime exception:
@Test
fun testBug() {
runBlocking {
println(f(2) { this() })
}
}
suspend fun <T> f(value: Int, block: suspend context(A) Int.() -> T): T = block(A(), value)
class A {
suspend operator fun Int.invoke() = this * 2
}
java.lang.ClassCastException: class A cannot be cast to class java.lang.Number
Is this a bug?
(Please ignore what the code actually does, it is just an excerpt to reproduce the issue.)ephemient
02/04/2023, 6:43 PM