I have a weird construction for which IntelliJ com...
# intellij
d
I have a weird construction for which IntelliJ complains:
Copy code
class 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?
This is a simplification of my actual code, in my actual code, I need access to T's class inside the private function
s
The compile error after you remove the
suspend
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
.
You can work around it by writing
test3<String> { test2() }
instead of
test3<String>(::test2)
. Since it’s an inlined lambda, the result should be identical.
s
I think there might be a known issue regarding suspend inline method references