commit | 7d36e3291a7221910912f55b3f6f5b8206c169e3 | [log] [tgz] |
---|---|---|
author | Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com> | Tue Aug 08 17:10:19 2023 +0200 |
committer | Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com> | Wed Aug 09 13:40:18 2023 +0200 |
tree | 376aae7b95f8a18333ccfc5797382c55cc04fd1e | |
parent | d6e760b47705faa002a4e6be689c74be80f0b362 [diff] |
[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
diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt index 5b36190..988e7aa 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt
@@ -100,7 +100,12 @@ // 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 /*
diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendUnitConversion.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendUnitConversion.kt index 78da8c3..47e501a 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendUnitConversion.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendUnitConversion.kt
@@ -12,8 +12,6 @@ } 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)