RTAkland
04/06/2025, 11:51 AMCaused by: java.lang.AssertionError: FUN name:testJvmBlocking visibility:public modality:FINAL <> () returnType:kotlin.Unit has no continuation; can't call FUN name:test visibility:public modality:FINAL <> ($this:test.Main) returnType:kotlin.Unit [suspend]
My code is here(just the insert function part):
val generatedFunction = pluginContext.irFactory.buildFun {
name = Name.identifier(newFunctionName)
isSuspend = false
visibility = func.visibility
returnType = func.returnType
modality = func.modality
startOffset = func.startOffset
endOffset = func.endOffset
}.apply {
parent = declaration
func.valueParameters.forEach { param -> valueParameters += param.copyTo(this) }
body = pluginContext.irBuilder(symbol).irBlockBody {
val suspendCall = pluginContext.irBuilder(func.symbol).run {
irCall(func).apply {
if (func.valueParameters.isNotEmpty()) {
func.valueParameters.forEachIndexed { index, param ->
putValueArgument(index, irGet(valueParameters[index]))
}
}
}
}
val runBlockingCall = pluginContext.irBuilder(func.symbol).run {
irCall(runBlockingFun).apply {
putTypeArgument(0, func.returnType)
putValueArgument(0, suspendCall)
}
}
+irReturn(runBlockingCall)
}
}
declaration.declarations += generatedFunction
Pavel Kunyavskiy [JB]
04/06/2025, 12:12 PMrunBlocking(foo())
, while you probably wanted to generate runBlocking { foo() }
.RTAkland
04/06/2025, 12:12 PMrunBlocking { foo() }
RTAkland
04/06/2025, 12:13 PMPavel Kunyavskiy [JB]
04/06/2025, 12:13 PMhfhbd
04/06/2025, 2:28 PMJavier
04/06/2025, 7:58 PMsimon.vergauwen
04/07/2025, 6:52 AMrunBlocking
for this. There exists a library for this though, https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin and it supports CompletableFuture
alongside runBlocking
and even has support for JsPromise
.