From 197cba35ebd8f168bd2de234fc394f18a237f211 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 26 Apr 2023 16:28:47 +0300 Subject: [PATCH] [K/N] Added couple of reproducers for KT-57791 --- .../backend.native/tests/build.gradle | 7 ++++ .../tests/framework/kt57791/knlibrary.kt | 19 +++++++++ .../tests/framework/kt57791/test.swift | 21 ++++++++++ .../tests/objcexport/expectedLazy.h | 39 +++++++++++++++++++ .../expectedLazyLegacySuspendUnit.h | 39 +++++++++++++++++++ .../tests/objcexport/expectedLazyNoGenerics.h | 39 +++++++++++++++++++ .../tests/objcexport/kt57791.kt | 27 +++++++++++++ .../tests/objcexport/kt57791.swift | 22 +++++++++++ 8 files changed, 213 insertions(+) create mode 100644 kotlin-native/backend.native/tests/framework/kt57791/knlibrary.kt create mode 100644 kotlin-native/backend.native/tests/framework/kt57791/test.swift create mode 100644 kotlin-native/backend.native/tests/objcexport/kt57791.kt create mode 100644 kotlin-native/backend.native/tests/objcexport/kt57791.swift diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 8c69e6e086f..8bbaee21ae6 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -6036,6 +6036,13 @@ if (isAppleTarget(project)) { swiftSources = ['framework/kt56233'] } + frameworkTest("testKt57791Framework") { + framework("Kt57791") { + sources = ['framework/kt57791'] + } + swiftSources = ['framework/kt57791'] + } + frameworkTest("testPermanentObjectsFramework") { enabled = isExperimentalMM && !isNoopGC // Requires gc to actually happen. framework("PermanentObjects") { diff --git a/kotlin-native/backend.native/tests/framework/kt57791/knlibrary.kt b/kotlin-native/backend.native/tests/framework/kt57791/knlibrary.kt new file mode 100644 index 00000000000..840c4a9405e --- /dev/null +++ b/kotlin-native/backend.native/tests/framework/kt57791/knlibrary.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +interface Foo { + fun bar(): String? +} + +internal class FooImplUnused : Foo { + override fun bar(): String? = null +} + +fun foobar(foo: Foo): Boolean { + val s = foo.bar() + if (s == null) + return false + return s == "zzz" +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/framework/kt57791/test.swift b/kotlin-native/backend.native/tests/framework/kt57791/test.swift new file mode 100644 index 00000000000..2effdd63ecd --- /dev/null +++ b/kotlin-native/backend.native/tests/framework/kt57791/test.swift @@ -0,0 +1,21 @@ +import Foundation +import Kt57791 + +class FooImpl : Foo { + func bar() -> String? { "zzz" } +} + +func testKt57791() throws { + try assertTrue(KnlibraryKt.foobar(foo: FooImpl())) +} + +class TestTests : TestProvider { + var tests: [TestCase] = [] + + init() { + providers.append(self) + tests = [ + TestCase(name: "Kt57791", method: withAutorelease(testKt57791)), + ] + } +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h index a3f230fa09a..34ccc5310e9 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h @@ -1315,6 +1315,45 @@ __attribute__((swift_name("CKt57373"))) @property (readonly) int32_t bar __attribute__((swift_name("bar"))); @end +__attribute__((swift_name("Ckt57791"))) +@interface KtCkt57791 : KtBase +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Okt57791"))) +@interface KtOkt57791 : KtCkt57791 ++ (instancetype)alloc __attribute__((unavailable)); ++ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable)); +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable)); ++ (instancetype)new __attribute__((unavailable)); ++ (instancetype)okt57791 __attribute__((swift_name("init()"))); +@property (class, readonly, getter=shared) KtOkt57791 *shared __attribute__((swift_name("shared"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Ckt57791Final"))) +@interface KtCkt57791Final : KtCkt57791 +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((swift_name("Foo"))) +@protocol KtFoo +@required +- (KtCkt57791Final *)getCkt57791 __attribute__((swift_name("getCkt57791()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Kt57791Kt"))) +@interface KtKt57791Kt : KtBase ++ (BOOL)foobarF:(BOOL)f foo:(id)foo __attribute__((swift_name("foobar(f:foo:)"))); +@end + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("LibraryKt"))) @interface KtLibraryKt : KtBase diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h index bc61603836b..9703b559018 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h @@ -1315,6 +1315,45 @@ __attribute__((swift_name("CKt57373"))) @property (readonly) int32_t bar __attribute__((swift_name("bar"))); @end +__attribute__((swift_name("Ckt57791"))) +@interface KtCkt57791 : KtBase +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Okt57791"))) +@interface KtOkt57791 : KtCkt57791 ++ (instancetype)alloc __attribute__((unavailable)); ++ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable)); +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable)); ++ (instancetype)new __attribute__((unavailable)); ++ (instancetype)okt57791 __attribute__((swift_name("init()"))); +@property (class, readonly, getter=shared) KtOkt57791 *shared __attribute__((swift_name("shared"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Ckt57791Final"))) +@interface KtCkt57791Final : KtCkt57791 +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((swift_name("Foo"))) +@protocol KtFoo +@required +- (KtCkt57791Final *)getCkt57791 __attribute__((swift_name("getCkt57791()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Kt57791Kt"))) +@interface KtKt57791Kt : KtBase ++ (BOOL)foobarF:(BOOL)f foo:(id)foo __attribute__((swift_name("foobar(f:foo:)"))); +@end + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("LibraryKt"))) @interface KtLibraryKt : KtBase diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h index a96e8bd67bd..c9b5d7daa2f 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h @@ -1315,6 +1315,45 @@ __attribute__((swift_name("CKt57373"))) @property (readonly) int32_t bar __attribute__((swift_name("bar"))); @end +__attribute__((swift_name("Ckt57791"))) +@interface KtCkt57791 : KtBase +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Okt57791"))) +@interface KtOkt57791 : KtCkt57791 ++ (instancetype)alloc __attribute__((unavailable)); ++ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable)); +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable)); ++ (instancetype)new __attribute__((unavailable)); ++ (instancetype)okt57791 __attribute__((swift_name("init()"))); +@property (class, readonly, getter=shared) KtOkt57791 *shared __attribute__((swift_name("shared"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Ckt57791Final"))) +@interface KtCkt57791Final : KtCkt57791 +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +- (int32_t)baz __attribute__((swift_name("baz()"))); +@end + +__attribute__((swift_name("Foo"))) +@protocol KtFoo +@required +- (KtCkt57791Final *)getCkt57791 __attribute__((swift_name("getCkt57791()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Kt57791Kt"))) +@interface KtKt57791Kt : KtBase ++ (BOOL)foobarF:(BOOL)f foo:(id)foo __attribute__((swift_name("foobar(f:foo:)"))); +@end + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("LibraryKt"))) @interface KtLibraryKt : KtBase diff --git a/kotlin-native/backend.native/tests/objcexport/kt57791.kt b/kotlin-native/backend.native/tests/objcexport/kt57791.kt new file mode 100644 index 00000000000..3cacd6cd2d4 --- /dev/null +++ b/kotlin-native/backend.native/tests/objcexport/kt57791.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kt57791 + +abstract class Ckt57791 { + abstract fun baz(): Int +} + +object Okt57791 : Ckt57791() { + override fun baz() = 117 +} + +class Ckt57791Final : Ckt57791() { + override fun baz() = 42 +} + +interface Foo { + fun getCkt57791(): Ckt57791Final +} + +fun foobar(f: Boolean, foo: Foo): Boolean { + val z = if (f) Okt57791 else foo.getCkt57791() + return z.baz() == 42 +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/objcexport/kt57791.swift b/kotlin-native/backend.native/tests/objcexport/kt57791.swift new file mode 100644 index 00000000000..10be74a93a3 --- /dev/null +++ b/kotlin-native/backend.native/tests/objcexport/kt57791.swift @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import Kt + +class FooImpl : Foo { + func getCkt57791() -> Ckt57791Final { return Ckt57791Final() } +} + +func testKt57791() throws { + try assertTrue(Kt57791Kt.foobar(f: false, foo: FooImpl())) +} + +class Kt57791Tests : SimpleTestProvider { + override init() { + super.init() + + test("testKt57791", testKt57791) + } +}