diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 6dc34ff6dbd..fb49bb1c8d0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -2148,7 +2148,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map, resultLifetime: Lifetime): LLVMValueRef { val result = call(llvmFunction, args, resultLifetime) - if (function.returnType.isNothing()) { + if (!function.isSuspend && function.returnType.isNothing()) { functionGenerationContext.unreachable() } diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 5efd08cca13..a228dbb2f7e 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -1543,6 +1543,11 @@ task coroutines_controlFlow_while2(type: RunKonanTest) { source = "codegen/coroutines/controlFlow_while2.kt" } +task coroutines_returnsNothing1(type: RunKonanTest) { + goldValue = "OK\n" + source = "codegen/coroutines/returnsNothing1.kt" +} + task coroutines_returnsUnit1(type: RunKonanTest) { goldValue = "117\ns1\n0\n" source = "codegen/coroutines/returnsUnit1.kt" diff --git a/backend.native/tests/codegen/coroutines/returnsNothing1.kt b/backend.native/tests/codegen/coroutines/returnsNothing1.kt new file mode 100644 index 00000000000..7f74e03b535 --- /dev/null +++ b/backend.native/tests/codegen/coroutines/returnsNothing1.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package codegen.coroutines.returnsNothing1 + +import kotlin.test.* + +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + companion object : EmptyContinuation() + override fun resumeWith(result: Result) { result.getOrThrow() } +} + +suspend fun suspendForever(): Int = suspendCoroutineUninterceptedOrReturn { + COROUTINE_SUSPENDED +} + +suspend fun foo(): Nothing { + suspendForever() + throw Error() +} + +suspend fun bar() { + foo() +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +@Test fun runTest() { + builder { + bar() + } + println("OK") +} \ No newline at end of file