Davio
11/23/2022, 9:31 AMclass Test {
suspend fun test1() = test3<String>(::test2)
suspend fun test2() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { }
private suspend inline fun <reified T> test3(block: suspend () -> Unit): List<T> {
block.invoke()
return listOf()
}
}
IntelliJ suggests that I can remove the suspend keyword from the lambda parameter of test3, but if I remove it, it no longer compiles.
The reason IntelliJ gives is Redundant 'suspend' modifier: lambda parameters of suspend function type uses existing continuation.
Is this an error in IntelliJ or the compiler?Davio
11/23/2022, 9:33 AMSam
11/23/2022, 9:36 AMsuspend
modifiers from the inline function just comes down to the type of the function reference ::test2
. I guess the compiler doesn’t have a rule to say that in the specific context of an inlined function parameter, it’s okay to convert from suspend () -> Unit
to () -> Unit
.Sam
11/23/2022, 9:37 AMtest3<String> { test2() }
instead of test3<String>(::test2)
. Since it’s an inlined lambda, the result should be identical.Starr
11/23/2022, 9:41 AMSam
11/23/2022, 9:43 AM