diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt index f6c21fb42c5..797deffd294 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt @@ -1204,7 +1204,11 @@ abstract class ObjCExportHeaderGenerator internal constructor( .forEach { val classDescriptor = mapper.getClassIfCategory(it) if (classDescriptor != null) { - extensions.getOrPut(classDescriptor, { mutableListOf() }) += it + // If a class is hidden from Objective-C API then it is meaningless + // to export its extensions. + if (!classDescriptor.isHiddenFromObjC()) { + extensions.getOrPut(classDescriptor, { mutableListOf() }) += it + } } else { topLevel.getOrPut(it.findSourceFile(), { mutableListOf() }) += it } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt index 52148b2621a..474ccb7b2c6 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt @@ -182,7 +182,11 @@ internal class ObjCExportLazyImpl( if ((it is KtFunction || it is KtProperty) && it.isPublic && !it.hasExpectModifier()) { val classDescriptor = getClassIfExtension(it) if (classDescriptor != null) { - extensions.getOrPut(classDescriptor, { mutableListOf() }) += it + // If a class is hidden from Objective-C API then it is meaningless + // to export its extensions. + if (!classDescriptor.isHiddenFromObjC()) { + extensions.getOrPut(classDescriptor, { mutableListOf() }) += it + } } else { topLevel += it } diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h index 34ccc5310e9..b3b167bc975 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h @@ -756,6 +756,7 @@ __attribute__((swift_name("WrapperOverUnavailable"))) __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("HiddenfromobjcKt"))) @interface KtHiddenfromobjcKt : KtBase ++ (id)doSomethingMeaningless:(NSString *)receiver another:(id)another __attribute__((swift_name("doSomethingMeaningless(_:another:)"))); + (id)useOfUnavailableClassParam:(id)param __attribute__((swift_name("useOfUnavailableClass(param:)"))); + (id _Nullable)useOfNullableUnavailableClassParam:(id _Nullable)param __attribute__((swift_name("useOfNullableUnavailableClass(param:)"))); + (id)produceUnavailable __attribute__((swift_name("produceUnavailable()"))); diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h index 9703b559018..f644474563a 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h @@ -756,6 +756,7 @@ __attribute__((swift_name("WrapperOverUnavailable"))) __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("HiddenfromobjcKt"))) @interface KtHiddenfromobjcKt : KtBase ++ (id)doSomethingMeaningless:(NSString *)receiver another:(id)another __attribute__((swift_name("doSomethingMeaningless(_:another:)"))); + (id)useOfUnavailableClassParam:(id)param __attribute__((swift_name("useOfUnavailableClass(param:)"))); + (id _Nullable)useOfNullableUnavailableClassParam:(id _Nullable)param __attribute__((swift_name("useOfNullableUnavailableClass(param:)"))); + (id)produceUnavailable __attribute__((swift_name("produceUnavailable()"))); diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h index c9b5d7daa2f..a56c18e83e4 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h @@ -756,6 +756,7 @@ __attribute__((swift_name("WrapperOverUnavailable"))) __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("HiddenfromobjcKt"))) @interface KtHiddenfromobjcKt : KtBase ++ (id)doSomethingMeaningless:(NSString *)receiver another:(id)another __attribute__((swift_name("doSomethingMeaningless(_:another:)"))); + (id)useOfUnavailableClassParam:(id)param __attribute__((swift_name("useOfUnavailableClass(param:)"))); + (id _Nullable)useOfNullableUnavailableClassParam:(id _Nullable)param __attribute__((swift_name("useOfNullableUnavailableClass(param:)"))); + (id)produceUnavailable __attribute__((swift_name("produceUnavailable()"))); diff --git a/kotlin-native/backend.native/tests/objcexport/hiddenfromobjc.kt b/kotlin-native/backend.native/tests/objcexport/hiddenfromobjc.kt index faa18f578fd..5e14670fe44 100644 --- a/kotlin-native/backend.native/tests/objcexport/hiddenfromobjc.kt +++ b/kotlin-native/backend.native/tests/objcexport/hiddenfromobjc.kt @@ -11,6 +11,15 @@ import kotlin.experimental.ExperimentalObjCRefinement @HiddenFromObjC data class ClassNotAvailableInSwift(val param: String) +// KT-58839 +fun ClassNotAvailableInSwift.doSomethingMeaningless(another: ClassNotAvailableInSwift): ClassNotAvailableInSwift { + return ClassNotAvailableInSwift(this.param + another.param) +} + +fun String.doSomethingMeaningless(another: ClassNotAvailableInSwift): ClassNotAvailableInSwift { + return ClassNotAvailableInSwift(this + another.param) +} + // Check that inner and nested classes are hidden if enclosing class is hidden @OptIn(ExperimentalObjCRefinement::class) @HiddenFromObjC