Add tests for case when result of tail-call suspend function returning

Unit is not Unit.
 #KT-34703 Fixed
This commit is contained in:
Ilmir Usmanov
2019-11-01 02:30:29 +03:00
parent ca527444cb
commit 8c079706a5
5 changed files with 104 additions and 5 deletions
@@ -0,0 +1,33 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FULL_JDK
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
var c: Continuation<*>? = null
suspend fun <T> tx(lambda: () -> T): T = suspendCoroutine { c = it; lambda() }
object Dummy
suspend fun suspect() {
tx { Dummy }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var res: Any? = null
builder {
res = suspect()
}
(c as? Continuation<Dummy>)?.resume(Dummy)
return if (res != Unit) "$res" else "OK"
}
@@ -0,0 +1,36 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FULL_JDK
// WITH_RUNTIME
// WITH_REFLECT
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
import kotlin.reflect.full.callSuspend
import kotlin.reflect.KCallable
var c: Continuation<*>? = null
suspend fun <T> tx(lambda: () -> T): T = suspendCoroutine { c = it; lambda() }
object Dummy
suspend fun suspect() {
tx { Dummy }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var res: Any? = null
builder {
res = (::suspect as KCallable<*>).callSuspend()
}
(c as? Continuation<Dummy>)?.resume(Dummy)
return if (res != Unit) "$res" else "OK"
}
@@ -8469,6 +8469,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tryCatch.kt", "kotlin.coroutines");
}
@TestMetadata("unitFunReturnsNonUnit.kt")
public void testUnitFunReturnsNonUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnit.kt");
}
@TestMetadata("unitFunReturnsNonUnitCallSuspend.kt")
public void testUnitFunReturnsNonUnitCallSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnitCallSuspend.kt");
}
@TestMetadata("unreachable.kt")
public void testUnreachable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");
@@ -8469,6 +8469,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tryCatch.kt", "kotlin.coroutines");
}
@TestMetadata("unitFunReturnsNonUnit.kt")
public void testUnitFunReturnsNonUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnit.kt");
}
@TestMetadata("unitFunReturnsNonUnitCallSuspend.kt")
public void testUnitFunReturnsNonUnitCallSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnitCallSuspend.kt");
}
@TestMetadata("unreachable.kt")
public void testUnreachable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");
@@ -18889,6 +18899,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class IsInitializedAndDeinitialize extends AbstractLightAnalysisModeTest {
@TestMetadata("isInitializedMultiFile.kt")
public void ignoreIsInitializedMultiFile() throws Exception {
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/isInitializedMultiFile.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -18912,11 +18927,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/innerSubclass.kt");
}
@TestMetadata("isInitializedMultiFile.kt")
public void testIsInitializedMultiFile() throws Exception {
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/isInitializedMultiFile.kt");
}
@TestMetadata("nonInlineLambda.kt")
public void testNonInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/nonInlineLambda.kt");
@@ -7404,6 +7404,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tryCatch.kt", "kotlin.coroutines");
}
@TestMetadata("unitFunReturnsNonUnit.kt")
public void testUnitFunReturnsNonUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnit.kt");
}
@TestMetadata("unitFunReturnsNonUnitCallSuspend.kt")
public void testUnitFunReturnsNonUnitCallSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnitCallSuspend.kt");
}
@TestMetadata("unreachable.kt")
public void testUnreachable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");