diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt index 67d7f57df29..3e06c627ed5 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.backend.konan.objcexport +import org.jetbrains.kotlin.backend.common.serialization.findSourceFile import org.jetbrains.kotlin.backend.konan.cKeywords import org.jetbrains.kotlin.backend.konan.descriptors.isArray import org.jetbrains.kotlin.backend.konan.descriptors.isInterface @@ -22,6 +23,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.descriptorUtil.isSubclassOf import org.jetbrains.kotlin.resolve.descriptorUtil.module +import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor import org.jetbrains.kotlin.resolve.source.PsiSourceFile internal interface ObjCExportNameTranslator { @@ -791,7 +793,7 @@ private fun ObjCExportMapper.canBeInheritedBySameClass( ): Boolean { if (this.isTopLevel(first) || this.isTopLevel(second)) { return this.isTopLevel(first) && this.isTopLevel(second) && - first.source.containingFile == second.source.containingFile + first.propertyIfAccessor.findSourceFile() == second.propertyIfAccessor.findSourceFile() } val firstClass = this.getClassIfCategory(first) ?: first.containingDeclaration as ClassDescriptor diff --git a/backend.native/tests/objcexport/expectedLazy.h b/backend.native/tests/objcexport/expectedLazy.h index 3373278b0a5..807bc2cd87d 100644 --- a/backend.native/tests/objcexport/expectedLazy.h +++ b/backend.native/tests/objcexport/expectedLazy.h @@ -607,6 +607,20 @@ __attribute__((swift_name("ThrowsEmptyKt"))) + (BOOL)throwsEmptyAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("throwsEmpty()"))); @end; +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("TopLevelManglingAKt"))) +@interface KtTopLevelManglingAKt : KtBase ++ (NSString *)foo __attribute__((swift_name("foo()"))); +@property (class, readonly) NSString *bar __attribute__((swift_name("bar"))); +@end; + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("TopLevelManglingBKt"))) +@interface KtTopLevelManglingBKt : KtBase ++ (NSString *)foo __attribute__((swift_name("foo()"))); +@property (class, readonly) NSString *bar __attribute__((swift_name("bar"))); +@end; + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("DelegateClass"))) @interface KtDelegateClass : KtBase diff --git a/backend.native/tests/objcexport/topLevelMangling.swift b/backend.native/tests/objcexport/topLevelMangling.swift new file mode 100644 index 00000000000..09f1762cc86 --- /dev/null +++ b/backend.native/tests/objcexport/topLevelMangling.swift @@ -0,0 +1,20 @@ +import Kt + +private func testFunctionsInDifferentFilesAreNotMangled() throws { + try assertEquals(actual: TopLevelManglingAKt.foo(), expected: "a1") + try assertEquals(actual: TopLevelManglingBKt.foo(), expected: "b1") +} + +private func testPropertiesInDifferentFilesAreNotMangled() throws { + try assertEquals(actual: TopLevelManglingAKt.bar, expected: "a2") + try assertEquals(actual: TopLevelManglingBKt.bar, expected: "b2") +} + +class TopLevelManglingTests : SimpleTestProvider { + override init() { + super.init() + + test("TestFunctionsInDifferentFilesAreNotMangled", testFunctionsInDifferentFilesAreNotMangled) + test("TestPropertiesInDifferentFilesAreNotMangled", testPropertiesInDifferentFilesAreNotMangled) + } +} diff --git a/backend.native/tests/objcexport/topLevelManglingA.kt b/backend.native/tests/objcexport/topLevelManglingA.kt new file mode 100644 index 00000000000..f192fcfac30 --- /dev/null +++ b/backend.native/tests/objcexport/topLevelManglingA.kt @@ -0,0 +1,4 @@ +package topLevelManglingA + +fun foo() = "a1" +val bar = "a2" diff --git a/backend.native/tests/objcexport/topLevelManglingB.kt b/backend.native/tests/objcexport/topLevelManglingB.kt new file mode 100644 index 00000000000..106840ed2dc --- /dev/null +++ b/backend.native/tests/objcexport/topLevelManglingB.kt @@ -0,0 +1,4 @@ +package topLevelManglingB + +fun foo() = "b1" +val bar = "b2"