From 29c30545e5311d28adc7ea9a33492c764c142d97 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 10 May 2017 16:41:51 +0300 Subject: [PATCH] Coroutines lowering: fixed bug appeared after merging with IR symbols --- .../kotlin/backend/konan/lower/SuspendFunctionsLowering.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SuspendFunctionsLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SuspendFunctionsLowering.kt index d5f98334d64..7e64844c873 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SuspendFunctionsLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SuspendFunctionsLowering.kt @@ -180,7 +180,11 @@ internal class SuspendFunctionsLowering(val context: Context): DeclarationContai private fun getSuspendFunctionKind(irFunction: IrFunction): SuspendFunctionKind { if (suspendLambdas.contains(irFunction.descriptor)) return SuspendFunctionKind.NEEDS_STATE_MACHINE // Suspend lambdas always need coroutine implementation. - val body = irFunction.body!! + + val body = irFunction.body + if (body == null) + return SuspendFunctionKind.NO_SUSPEND_CALLS + var numberOfSuspendCalls = 0 body.acceptVoid(object: IrElementVisitorVoid { override fun visitElement(element: IrElement) { @@ -197,6 +201,7 @@ internal class SuspendFunctionsLowering(val context: Context): DeclarationContai // It is important to optimize the case where there is only one suspend call and it is the last statement // because we don't need to build a fat coroutine class in that case. // This happens a lot in practise because of suspend functions with default arguments. + // TODO: use TailRecursionCallsCollector. val lastStatement = (body as IrBlockBody).statements.lastOrNull() val lastCall = when (lastStatement) { is IrCall -> lastStatement