diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/suspendModifier.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/suspendModifier.kt new file mode 100644 index 00000000000..3607b1009c4 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/suspendModifier.kt @@ -0,0 +1,31 @@ +// WITH_RUNTIME +// WITH_COROUTINES +import helpers.* +import kotlin.coroutines.experimental.* +import kotlin.coroutines.experimental.intrinsics.* + +suspend fun suspendHere(v: String): String = suspendCoroutineOrReturn { x -> + x.resume(v) + COROUTINE_SUSPENDED +} + +suspend fun foo(): String { + var a = "OK" + var i = 0 + val x = suspend { + suspendHere(a[i++].toString()) + } + + return x() + x.invoke() +} + + +fun box(): String { + var result = "" + + suspend { + result = foo() + }.startCoroutine(EmptyContinuation) + + return result +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt new file mode 100644 index 00000000000..ba70c569ef2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt @@ -0,0 +1,20 @@ +import kotlin.coroutines.experimental.Continuation +import kotlin.coroutines.experimental.CoroutineContext +import kotlin.coroutines.experimental.startCoroutine + +fun bar() { + suspend { + println() + }.startCoroutine(object: Continuation { + override val context: CoroutineContext + get() = TODO("not implemented") + + override fun resume(value: Unit) { + TODO("not implemented") + } + + override fun resumeWithException(exception: Throwable) { + TODO("not implemented") + } + }) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.txt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.txt new file mode 100644 index 00000000000..19a5b8840b9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.txt @@ -0,0 +1,3 @@ +package + +public fun bar(): kotlin.Unit diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e413ed9deee..3d77f92182d 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6571,6 +6571,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/simple.kt"); doTest(fileName); } + + @TestMetadata("suspendModifier.kt") + public void testSuspendModifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/suspendModifier.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index f7ec881ddb8..07ed01870c8 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1398,6 +1398,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW doTest(fileName); } + @TestMetadata("suspendLambda.kt") + public void testSuspendLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt"); + doTest(fileName); + } + @TestMetadata("suspendOverridability.kt") public void testSuspendOverridability() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index c1481d794e7..19d0e7e583e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -1398,6 +1398,12 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno doTest(fileName); } + @TestMetadata("suspendLambda.kt") + public void testSuspendLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt"); + doTest(fileName); + } + @TestMetadata("suspendOverridability.kt") public void testSuspendOverridability() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index af72d38cfb5..fe0773288e0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6571,6 +6571,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/simple.kt"); doTest(fileName); } + + @TestMetadata("suspendModifier.kt") + public void testSuspendModifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/suspendModifier.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index ba6ef8d8c6b..411c91fcf71 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6571,6 +6571,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/simple.kt"); doTest(fileName); } + + @TestMetadata("suspendModifier.kt") + public void testSuspendModifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/suspendModifier.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 89f6b21f5e9..a88eb441464 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -7147,6 +7147,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/simple.kt"); doTest(fileName); } + + @TestMetadata("suspendModifier.kt") + public void testSuspendModifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionTypeCall/suspendModifier.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations") diff --git a/libraries/stdlib/src/kotlin/util/Suspend.kt b/libraries/stdlib/src/kotlin/util/Suspend.kt new file mode 100644 index 00000000000..18a5e8701cd --- /dev/null +++ b/libraries/stdlib/src/kotlin/util/Suspend.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package kotlin + +@kotlin.internal.InlineOnly +public inline fun suspend(noinline block: suspend () -> R): suspend () -> R = block