Rafael Tonholo
02/15/2025, 6:45 PM1.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:
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:
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.Rafael Tonholo
02/15/2025, 6:46 PMhfhbd
02/15/2025, 7:09 PMhfhbd
02/15/2025, 7:12 PMephemient
02/15/2025, 7:40 PMIvan Kylchik
02/17/2025, 5:56 PM