https://kotlinlang.org logo
#coroutines
Title
# coroutines
u

uli

09/26/2019, 10:55 AM
2) Is it a compiler bug that suspending function references are no longer accepted if I remove the suspend modifier?
d

Dico

09/26/2019, 10:57 AM
Example?
u

uli

09/26/2019, 11:04 AM
Copy code
class X {

    suspend fun suspending() {}

    suspend fun test1() {
        // Error goes away if we add suspend modifier to logError an it's parameter block
        // But then IDE complains about redundant suspend modifier
        logError(::suspending)
    }

    suspend fun test2() {
        logError { suspending() }
    }

    inline fun logError(block: () -> Unit) {
        try {
            block()
        } catch (e: Exception) {
            //Log Exception
        }
    }
}
v

Vsevolod Tolstopyatov [JB]

09/26/2019, 11:22 AM
It is both bug in the compiler and in the inspection 🙂 https://youtrack.jetbrains.com/issue/KT-30536
u

uli

09/26/2019, 11:52 AM
@Vsevolod Tolstopyatov [JB] thanks for opening the ticket and especially for pointing out the name of the inspection 🙂
And now I get a
wrong bytecode generated
error for this:
Copy code
class X {

    suspend fun suspending() {}

    suspend fun test() {
        logError(::suspending)
    }

    suspend inline fun runBlock(block: suspend () -> Unit) {
        logError(block)
    }

    suspend inline fun logError(block: suspend () -> Unit) {
        try {
            block()
        } catch (e: Exception) {
            //Log Exception
        }
    }
}
i

Ilmir Usmanov [JB]

09/26/2019, 12:33 PM
@uli Can you, please, open a separate ticket for this case? I'll take a look.
u
3 Views