One Off the Slack: Flow and Experimental Compilers
On 18 April 2020, Jitin Sharma was inquiring about a build failure when
trying to use Flow
:
Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'collect' into
public suspend inline fun <T> kotlinx.coroutines.flow.Flow<T>.collect(crossinline action: suspend (T) -> kotlin.Unit, `$completion`: kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Any? defined in kotlinx.coroutines.flow
As was noted in a Kotlin coroutines issue from October 2019, the problem is that, right now, Jetpack Compose is dependent upon a compiler and compiler plugin that are:
- Experimental, and
- A bit old, relative to coroutines
So, at least through the dev09
release, using coroutines with Compose is likely to
cause problems.
In the Slack thread, Google’s Adam Powell points out that improvements are coming soon:
An updated version [of the compiler+plugin] landed this past week but it’s still not up to current yet, it’ll be out in dev10. In that version quite a lot more works around coroutines, but I’ve heard reports from the team that there are still some issues around Flow.
I’m not sure for certain yet but I suspect it might be related to suspend+crossinline being used together. We’re working on getting fully up to date for this.
So, in a week or two (hopefully! 🤞), we will be able to upgrade and get more
of our coroutines on with Compose. Note that this probably requires updating the
kotlinCompilerVersion
in our Gradle build scripts.
Read the original thread in the kotlinlang Slack workspace. Not a member? Join that Slack workspace here!