Hello, I'm trying to upgrade kotlinx-coroutines fr...
# coroutines
r
Hello, I'm trying to upgrade kotlinx-coroutines from
1.9.0
to
1.10.1
, and since
1.10.0
, I've started experiencing a weird backend compiler issue. It works fine when I am using
1.9.0
, but after upgrading to
1.10.0
or
1.10.1
, I only get the following error when compiling the code:
Copy code
Caused by: java.lang.AssertionError: Error occurred while optimizing an expression:
CALL 'public open fun plus (context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext [fake_override,operator] declared in kotlinx.coroutines.CompletableJob' type=kotlin.coroutines.CoroutineContext origin=PLUS
  $this: CALL 'public final fun SupervisorJob (parent: kotlinx.coroutines.Job?): kotlinx.coroutines.CompletableJob declared in kotlinx.coroutines.SupervisorKt' type=kotlinx.coroutines.CompletableJob origin=null
  context: CALL 'public final fun <get-IO> (): kotlinx.coroutines.CoroutineDispatcher declared in kotlinx.coroutines.Dispatchers' type=kotlinx.coroutines.CoroutineDispatcher origin=GET_PROPERTY
    $this: GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Dispatchers modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlinx.coroutines.Dispatchers

        ... 108 more
Caused by: java.lang.AssertionError: Type should be an array, but was KClass<out Annotation>: [NormalClass(value=kotlinx/coroutines/InternalForInheritanceCoroutinesApi)]
I don't see any errors on the IDE, btw. I have added the full stack trace in the thread comments. Versions I'm using: • kotlin = "2.1.10" • kotlinx-coroutines = "1.10.1" For context, I'm using kotlinx-coroutines to run a Gradle Task operation in parallel by using
async
. In my Gradle Task implementation, I used creating the
CoroutineScope
by declaring it such as:
Copy code
abstract class ParseSvgToComposeIconTask {
    private val scope = CoroutineScope(SupervisorJob() + <http://Dispatchers.IO|Dispatchers.IO>)

    @TaskAction
    fun run() = runBlocking { processFiles(/* bunch of params */) }

    private suspend fun processFiles(/* bunch of params */) {
        files.map { path -> scope.async { path.process(/* bunch of params */) } }
    }

    private suspend fun Path.process(/* bunch of params */) { /* IO operation */ }
}
I found out that to fix the problem, I just need to remove
<http://Dispatchers.IO|Dispatchers.IO>
from the
CoroutineScope(SupervisorJob() + <http://Dispatchers.IO|Dispatchers.IO>)
and use the
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
or
async(<http://Dispatchers.IO|Dispatchers.IO>)
where I want. Still, I wonder if this isn't a bug since it is very common to create a scope close to a dispatcher by using the
+
operator. Maybe I'm doing something wrong, or am I missing something else, and I would appreciate any of your input. Thanks in advance.
The full stack trace:
h
Gradle itself heavily uses IO operations. If you just parse svg files and process them locally, you don’t need coroutines and parallel processing at all. And you should not use coroutines in tasks, but in workers to isolate your dependencies. The workers can run in parallel too.
Regarding the internal compiler bug you got, it might be related to the Kotlin api version set by Gradle.
e
Gradle has a fixed version of Kotlin in its runtime. you can't just use arbitrary new Kotlin versions or libraries within a Gradle plugin, or anything else loaded into a Gradle buildscript classpath.
i
Hi! I am looking into this issue right now. See KT-74984. Also you can apply the workaround provided in the comments.
thank you color 1