[Wasm] Fix SuspendFunctionKind.DELEGATING bug (KT-60700)

When detecting function delegation at the last statement position we
need to make sure that delegating call has unit return type, otherwise
we would try to return non-Unit value from a parent function returning
 Unit

^KT-60700 Fixed
This commit is contained in:
Svyatoslav Kuzmich
2023-08-08 17:10:19 +02:00
committed by Space Team
parent ecd06ac47b
commit 432c9fe592
2 changed files with 6 additions and 3 deletions
@@ -100,7 +100,12 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
// This happens a lot in practice because of suspend functions with default arguments.
// TODO: use TailRecursionCallsCollector.
val lastCall = when (val lastStatement = (body as IrBlockBody).statements.lastOrNull()) {
is IrCall -> lastStatement
is IrCall ->
// Delegation to call without return can only be performed to Unit-returning function call from Unit-returning function
if (lastStatement.type == context.irBuiltIns.unitType && function.returnType == context.irBuiltIns.unitType)
lastStatement
else
null
is IrReturn -> {
var value: IrElement = lastStatement
/*
@@ -12,8 +12,6 @@ suspend fun bar(): Int = suspendCoroutineUninterceptedOrReturn<Int> {
}
fun box(): String {
return "OK" // KT-60700 Test is hardmuted due to WASM failures on Win&Mac, but not on Linux. So, `// IGNORE_BACKEND: WASM` does not help
var result = ""
suspend {
foo(::bar)