Fix incorrect code generation for Nothing-returning suspend calls

#KT-30642 Fixed
This commit is contained in:
SvyatoslavScherbina
2019-03-27 16:57:45 +03:00
committed by GitHub
parent b22fa985e0
commit b870ce987a
3 changed files with 46 additions and 1 deletions
@@ -2148,7 +2148,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
private fun call(function: IrFunction, llvmFunction: LLVMValueRef, args: List<LLVMValueRef>,
resultLifetime: Lifetime): LLVMValueRef {
val result = call(llvmFunction, args, resultLifetime)
if (function.returnType.isNothing()) {
if (!function.isSuspend && function.returnType.isNothing()) {
functionGenerationContext.unreachable()
}
+5
View File
@@ -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"
@@ -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<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { 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")
}