diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 5d3ca14f747..c6430455992 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -1695,6 +1695,26 @@ task coroutines_anonymousObject(type: KonanLocalTest) { source = "codegen/coroutines/anonymousObject.kt" } +task coroutines_functionReference_simple(type: KonanLocalTest) { + goldValue = "42\n" + source = "codegen/coroutines/functionReference_simple.kt" +} + +task coroutines_functionReference_eqeq_name(type: KonanLocalTest) { + goldValue = "" + source = "codegen/coroutines/functionReference_eqeq_name.kt" +} + +task coroutines_functionReference_invokeAsFunction(type: KonanLocalTest) { + goldValue = "159\n" + source = "codegen/coroutines/functionReference_invokeAsFunction.kt" +} + +task coroutines_functionReference_lambdaAsSuspendLambda(type: KonanLocalTest) { + goldValue = "" + source = "codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt" +} + task AbstractMutableCollection(type: KonanLocalTest) { expectedExitStatus = 0 source = "runtime/collections/AbstractMutableCollection.kt" diff --git a/backend.native/tests/codegen/coroutines/functionReference_eqeq_name.kt b/backend.native/tests/codegen/coroutines/functionReference_eqeq_name.kt new file mode 100644 index 00000000000..600284984de --- /dev/null +++ b/backend.native/tests/codegen/coroutines/functionReference_eqeq_name.kt @@ -0,0 +1,32 @@ +/* + * 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.functionReference_eqeq_name + +import kotlin.test.* + +suspend fun foo(x: Int) = x + +class Foo(val x: Int) { + suspend fun bar() = x +} + +@Test fun runTest() { + val ref1 = ::foo + val rec = Foo(42) + val ref2 = rec::bar + val ref3 = ::foo + val ref4 = Foo(42)::bar + val ref5 = rec::bar + val ref6 = Foo::bar + assertEquals("foo", ref1.name) + assertEquals("bar", ref2.name) + assertEquals("bar", ref6.name) + assertFalse(ref1 == ref2) + assertTrue(ref1 == ref3) + assertFalse(ref2 == ref4) + assertTrue(ref2 == ref5) + assertFalse(ref6 == ref2) +} diff --git a/backend.native/tests/codegen/coroutines/functionReference_invokeAsFunction.kt b/backend.native/tests/codegen/coroutines/functionReference_invokeAsFunction.kt new file mode 100644 index 00000000000..0d64ac94c97 --- /dev/null +++ b/backend.native/tests/codegen/coroutines/functionReference_invokeAsFunction.kt @@ -0,0 +1,28 @@ +/* + * 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.functionReference_invokeAsFunction + +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() } +} + +class Foo(val x: Int) { + suspend fun bar(y: Int) = foo(y) + x +} + +suspend fun foo(x: Int) = x + +@Test fun runTest() { + val ref = Foo(42)::bar + + println((ref as Function2, Any?>)(117, EmptyContinuation)) +} diff --git a/backend.native/tests/codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt b/backend.native/tests/codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt new file mode 100644 index 00000000000..df9eb23b52a --- /dev/null +++ b/backend.native/tests/codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt @@ -0,0 +1,19 @@ +/* + * 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.functionReference_lambdaAsSuspendLambda + +import kotlin.test.* + +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun foo(block: (Continuation) -> Any?) { + block as (suspend () -> Unit) +} + +@Test fun runTest() { + foo {} +} \ No newline at end of file diff --git a/backend.native/tests/codegen/coroutines/functionReference_simple.kt b/backend.native/tests/codegen/coroutines/functionReference_simple.kt new file mode 100644 index 00000000000..d574dc9d373 --- /dev/null +++ b/backend.native/tests/codegen/coroutines/functionReference_simple.kt @@ -0,0 +1,39 @@ +/* + * 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.functionReference_simple + +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 suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x -> + x.resume(42) + COROUTINE_SUSPENDED +} + +suspend fun foo(x: suspend () -> Int) = x() + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +@Test fun runTest() { + var result = 0 + + val ref = ::suspendHere + + builder { + result = foo(ref) + } + + println(result) +}