From 8c079706a54621844ef65d934229d96a836d4e9f Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Fri, 1 Nov 2019 02:30:29 +0300 Subject: [PATCH] Add tests for case when result of tail-call suspend function returning Unit is not Unit. #KT-34703 Fixed --- .../unitFunReturnsNonUnit.kt | 33 +++++++++++++++++ .../unitFunReturnsNonUnitCallSuspend.kt | 36 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 10 ++++++ .../LightAnalysisModeTestGenerated.java | 20 ++++++++--- .../ir/IrBlackBoxCodegenTestGenerated.java | 10 ++++++ 5 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnit.kt create mode 100644 compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnitCallSuspend.kt diff --git a/compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnit.kt b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnit.kt new file mode 100644 index 00000000000..078f17b3bdb --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnit.kt @@ -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 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)?.resume(Dummy) + + return if (res != Unit) "$res" else "OK" +} diff --git a/compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnitCallSuspend.kt b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnitCallSuspend.kt new file mode 100644 index 00000000000..8a5f03491db --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/unitFunReturnsNonUnitCallSuspend.kt @@ -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 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)?.resume(Dummy) + + return if (res != Unit) "$res" else "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index da15db896a7..2001f8288b9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8df402e74e1..d58b4691b6d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 787b47ab3c0..36df8857fce 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -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");