From 3378aeddb5c1046e981c4163585efd0f152a6915 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Thu, 28 Jan 2021 16:42:38 +0100 Subject: [PATCH] [interop][c][reverse][test] (KT-36639) --- .../backend.native/tests/build.gradle | 13 +++++++++ .../tests/produce_dynamic/kt-36639/main.c | 28 +++++++++++++++++++ .../tests/produce_dynamic/kt-36639/main.kt | 21 ++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.c create mode 100644 kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index edf0aa019ea..b6103d957d6 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4367,6 +4367,19 @@ dynamicTest("produce_dynamic") { "Error handler: kotlin.Error: Expected error\n" } +dynamicTest("kt36639") { + disabled = (project.target.name != project.hostName) + source = "produce_dynamic/kt-36639/main.kt" + cSource = "$projectDir/produce_dynamic/kt-36639/main.c" + goldValue = """|CFoo1::extfoo + |CFoo1::extfoo + |CFoo2::extfoo + |CFoo2::extfoo + |Int::extfoo + |Int::extfoo + |""".stripMargin() +} + dynamicTest("interop_concurrentRuntime") { disabled = (project.target.name != project.hostName) disabled = true // KT-43180 diff --git a/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.c b/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.c new file mode 100644 index 00000000000..b2236dbc277 --- /dev/null +++ b/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.c @@ -0,0 +1,28 @@ +#include "testlib_api.h" + +#define __ testlib_symbols()-> +#define T_(x) testlib_kref_ ## x + + +int +main() { + T_(CFoo1) foo1 = __ kotlin.root.CFoo1.CFoo1(); + T_(CFoo2) foo2 = __ kotlin.root.CFoo2.CFoo2(); + T_(kotlin_Int) intV = __ createNullableInt(42); + T_(kotlin_Any) any; + T_(Foo) foo = { .pinned = foo1.pinned }; + + any.pinned = foo1.pinned; + __ kotlin.root.CFoo1.callMe(foo1, any); + __ kotlin.root.Foo.extfoo(foo, any); + any.pinned = foo2.pinned; + __ kotlin.root.CFoo1.callMe(foo1, any); + __ kotlin.root.Foo.extfoo(foo, any); + any.pinned = intV.pinned; + __ kotlin.root.CFoo1.callMe(foo1, any); + __ kotlin.root.Foo.extfoo(foo, any); + + __ DisposeStablePointer(foo1.pinned); + __ DisposeStablePointer(foo2.pinned); + __ DisposeStablePointer(intV.pinned); +} diff --git a/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.kt b/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.kt new file mode 100644 index 00000000000..236d1337aa2 --- /dev/null +++ b/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.kt @@ -0,0 +1,21 @@ +interface Foo { + fun Any.extfoo() +} + +class CFoo1:Foo { + override fun Any.extfoo() { + when(this) { + is CFoo1 -> println("CFoo1::extfoo") + is CFoo2 -> println("CFoo2::extfoo") + is Int -> println("Int::extfoo") + } + } + + fun callMe(arg: Any) = arg.extfoo() +} + +class CFoo2:Foo { + override fun Any.extfoo() { + TODO("Not yet implemented") + } +} \ No newline at end of file