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