From 35e94a1ef7a479622ed5e0264fc5d723f2124d3d Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Thu, 22 Dec 2022 09:50:03 +0100 Subject: [PATCH] [K/N] Fully rename parameters based on ObjCName annotations. The original name was still left in the ObjC code for cases such as: ``` class A(@property:ObjCName("y") @ObjCName("y") val x: Int) ``` which compiled to: ``` @interface FrameworkA : FrameworkBase - (instancetype)initWithY:(int32_t)x __attribute__((swift_name("init(y:)"))) __attribute__((objc_designated_initializer)); @property (readonly) int32_t y __attribute__((swift_name("y"))); @end ``` This change renames the `x` ocurrence in `initWithY` which is important in case ObjCName is used to avoid using names that conflict with ObjC preprocessor macros. --- .../objcexport/ObjCExportHeaderGenerator.kt | 2 +- .../konan/objcexport/ObjCExportNamer.kt | 3 ++ .../tests/objcexport/expectedLazy.h | 29 ++++++++++++------- .../expectedLazyLegacySuspendUnit.h | 29 ++++++++++++------- .../tests/objcexport/expectedLazyNoGenerics.h | 29 ++++++++++++------- .../tests/objcexport/objCName.swift | 6 ++++ .../tests/objcexport/objCNameB.kt | 2 ++ 7 files changed, 66 insertions(+), 34 deletions(-) mode change 100644 => 100755 kotlin-native/backend.native/tests/objcexport/expectedLazy.h 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 6ab6190e279..b23f1236d53 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 @@ -649,7 +649,7 @@ internal class ObjCExportTranslatorImpl( when { p is ReceiverParameterDescriptor -> "receiver" method is PropertySetterDescriptor -> "value" - else -> p.name.asString() + else -> namer.getParameterName(p) } } MethodBridgeValueParameter.ErrorOutParameter -> "error" diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt index a321ddd69bd..705f9fc55eb 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt @@ -61,6 +61,7 @@ interface ObjCExportNamer { fun getFileClassName(file: SourceFile): ClassOrProtocolName fun getClassOrProtocolName(descriptor: ClassDescriptor): ClassOrProtocolName fun getSelector(method: FunctionDescriptor): String + fun getParameterName(parameter: ParameterDescriptor): String fun getSwiftName(method: FunctionDescriptor): String fun getPropertyName(property: PropertyDescriptor): PropertyName fun getObjectInstanceSelector(descriptor: ClassDescriptor): String @@ -480,6 +481,8 @@ internal class ObjCExportNamerImpl( append(objCName.asIdentifier(forSwift)) } + override fun getParameterName(parameter: ParameterDescriptor): String = parameter.getObjCName().asString(forSwift = false) + override fun getSelector(method: FunctionDescriptor): String = methodSelectors.getOrPut(method) { assert(mapper.isBaseMethod(method)) diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h old mode 100644 new mode 100755 index 2ea3e68bbbe..0a0baee9aea --- a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h @@ -302,7 +302,7 @@ __attribute__((swift_name("suspendFunctionChild1"))) * @note This method converts instances of CancellationException to errors. * Other uncaught Kotlin exceptions are fatal. */ -- (void)invokeP1:(NSString *)s completionHandler:(void (^)(NSString * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("invoke(p1:completionHandler:)"))); +- (void)invokeP1:(NSString *)p1 completionHandler:(void (^)(NSString * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("invoke(p1:completionHandler:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1269,8 +1269,8 @@ __attribute__((swift_name("ObjCNameAKt"))) @interface KtObjCNameAKt : KtBase + (NSString *)withUserId:(NSString *)userId __attribute__((swift_name("with(userId:)"))); + (BOOL)supportsFeatures:(BOOL)features __attribute__((swift_name("supports(_:)"))); -+ (NSString *)scanForPeripheralsWithServices:(int32_t)serviceUUIDs options:(NSString *)options __attribute__((swift_name("scanForPeripherals(withServices:options:)"))); -+ (NSString *)registerForConnectionEventsWithOptions:(NSString *)options __attribute__((swift_name("registerForConnectionEvents(options:)"))); ++ (NSString *)scanForPeripheralsWithServices:(int32_t)withServices options:(NSString *)options __attribute__((swift_name("scanForPeripherals(withServices:options:)"))); ++ (NSString *)registerForConnectionEventsWithOptions:(NSString *)withOptions __attribute__((swift_name("registerForConnectionEvents(options:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1286,14 +1286,14 @@ __attribute__((swift_name("MySwiftArray"))) @interface KtMyObjCArray : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)indexOfObject:(int32_t)element __attribute__((swift_name("index(of:)"))); +- (int32_t)indexOfObject:(int32_t)object __attribute__((swift_name("index(of:)"))); @property (readonly) int32_t count __attribute__((swift_name("count"))); @end __attribute__((swift_name("ObjCNameI1"))) @protocol KtObjCNameI1 @required -- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)param __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); +- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)otherParam __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); @property (readonly) int32_t someOtherValue __attribute__((swift_name("someOtherValue"))); @end @@ -1302,7 +1302,7 @@ __attribute__((swift_name("SwiftNameC2"))) @interface KtObjCNameC2 : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)param __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); +- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)otherParam __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); @property int32_t someOtherValue __attribute__((swift_name("someOtherValue"))); @end @@ -1342,7 +1342,7 @@ __attribute__((swift_name("ObjCNameC4"))) @interface KtObjCNameC4 : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)fooObjCReceiver:(int32_t)receiver objCParam:(int32_t)param __attribute__((swift_name("foo(objCReceiver:objCParam:)"))); +- (int32_t)fooObjCReceiver:(int32_t)receiver objCParam:(int32_t)objCParam __attribute__((swift_name("foo(objCReceiver:objCParam:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1376,6 +1376,13 @@ __attribute__((swift_name("ObjCNameSwiftEnum.Companion"))) - (int32_t)foo __attribute__((swift_name("foo()"))); @end +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("ObjCAvoidPreprocessorName"))) +@interface KtObjCAvoidPreprocessorName : KtBase +- (instancetype)initWithTime:(int32_t)time __attribute__((swift_name("init(time:)"))) __attribute__((objc_designated_initializer)); +@property (readonly) int32_t time __attribute__((swift_name("time"))); +@end + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("ObjCNameBKt"))) @interface KtObjCNameBKt : KtBase @@ -2184,16 +2191,16 @@ __attribute__((swift_name("TransformIntToString"))) @interface KtTransformIntToString : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (NSString *)mapValue:(KtInt *)intValue __attribute__((swift_name("map(value:)"))); -- (NSString *)mapIntValue:(int32_t)intValue __attribute__((swift_name("map(intValue:)"))); +- (NSString *)mapValue:(KtInt *)value __attribute__((swift_name("map(value:)"))); +- (NSString *)mapIntValue:(int32_t)value __attribute__((swift_name("map(intValue:)"))); @end __attribute__((swift_name("TransformIntToDecimalString"))) @interface KtTransformIntToDecimalString : KtTransformIntToString - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (NSString *)mapValue:(KtInt *)intValue __attribute__((swift_name("map(value:)"))); -- (NSString *)mapIntValue:(int32_t)intValue __attribute__((swift_name("map(intValue:)"))); +- (NSString *)mapValue:(KtInt *)value __attribute__((swift_name("map(value:)"))); +- (NSString *)mapIntValue:(int32_t)value __attribute__((swift_name("map(intValue:)"))); @end __attribute__((swift_name("TransformIntToLong"))) diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h index b6f777a9676..5e9677f4801 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h @@ -302,7 +302,7 @@ __attribute__((swift_name("suspendFunctionChild1"))) * @note This method converts instances of CancellationException to errors. * Other uncaught Kotlin exceptions are fatal. */ -- (void)invokeP1:(NSString *)s completionHandler:(void (^)(NSString * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("invoke(p1:completionHandler:)"))); +- (void)invokeP1:(NSString *)p1 completionHandler:(void (^)(NSString * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("invoke(p1:completionHandler:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1204,8 +1204,8 @@ __attribute__((swift_name("ObjCNameAKt"))) @interface KtObjCNameAKt : KtBase + (NSString *)withUserId:(NSString *)userId __attribute__((swift_name("with(userId:)"))); + (BOOL)supportsFeatures:(BOOL)features __attribute__((swift_name("supports(_:)"))); -+ (NSString *)scanForPeripheralsWithServices:(int32_t)serviceUUIDs options:(NSString *)options __attribute__((swift_name("scanForPeripherals(withServices:options:)"))); -+ (NSString *)registerForConnectionEventsWithOptions:(NSString *)options __attribute__((swift_name("registerForConnectionEvents(options:)"))); ++ (NSString *)scanForPeripheralsWithServices:(int32_t)withServices options:(NSString *)options __attribute__((swift_name("scanForPeripherals(withServices:options:)"))); ++ (NSString *)registerForConnectionEventsWithOptions:(NSString *)withOptions __attribute__((swift_name("registerForConnectionEvents(options:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1221,14 +1221,14 @@ __attribute__((swift_name("MySwiftArray"))) @interface KtMyObjCArray : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)indexOfObject:(int32_t)element __attribute__((swift_name("index(of:)"))); +- (int32_t)indexOfObject:(int32_t)object __attribute__((swift_name("index(of:)"))); @property (readonly) int32_t count __attribute__((swift_name("count"))); @end __attribute__((swift_name("ObjCNameI1"))) @protocol KtObjCNameI1 @required -- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)param __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); +- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)otherParam __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); @property (readonly) int32_t someOtherValue __attribute__((swift_name("someOtherValue"))); @end @@ -1237,7 +1237,7 @@ __attribute__((swift_name("SwiftNameC2"))) @interface KtObjCNameC2 : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)param __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); +- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)otherParam __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); @property int32_t someOtherValue __attribute__((swift_name("someOtherValue"))); @end @@ -1277,7 +1277,7 @@ __attribute__((swift_name("ObjCNameC4"))) @interface KtObjCNameC4 : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)fooObjCReceiver:(int32_t)receiver objCParam:(int32_t)param __attribute__((swift_name("foo(objCReceiver:objCParam:)"))); +- (int32_t)fooObjCReceiver:(int32_t)receiver objCParam:(int32_t)objCParam __attribute__((swift_name("foo(objCReceiver:objCParam:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1311,6 +1311,13 @@ __attribute__((swift_name("ObjCNameSwiftEnum.Companion"))) - (int32_t)foo __attribute__((swift_name("foo()"))); @end +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("ObjCAvoidPreprocessorName"))) +@interface KtObjCAvoidPreprocessorName : KtBase +- (instancetype)initWithTime:(int32_t)time __attribute__((swift_name("init(time:)"))) __attribute__((objc_designated_initializer)); +@property (readonly) int32_t time __attribute__((swift_name("time"))); +@end + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("ObjCNameBKt"))) @interface KtObjCNameBKt : KtBase @@ -2119,16 +2126,16 @@ __attribute__((swift_name("TransformIntToString"))) @interface KtTransformIntToString : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (NSString *)mapValue:(KtInt *)intValue __attribute__((swift_name("map(value:)"))); -- (NSString *)mapIntValue:(int32_t)intValue __attribute__((swift_name("map(intValue:)"))); +- (NSString *)mapValue:(KtInt *)value __attribute__((swift_name("map(value:)"))); +- (NSString *)mapIntValue:(int32_t)value __attribute__((swift_name("map(intValue:)"))); @end __attribute__((swift_name("TransformIntToDecimalString"))) @interface KtTransformIntToDecimalString : KtTransformIntToString - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (NSString *)mapValue:(KtInt *)intValue __attribute__((swift_name("map(value:)"))); -- (NSString *)mapIntValue:(int32_t)intValue __attribute__((swift_name("map(intValue:)"))); +- (NSString *)mapValue:(KtInt *)value __attribute__((swift_name("map(value:)"))); +- (NSString *)mapIntValue:(int32_t)value __attribute__((swift_name("map(intValue:)"))); @end __attribute__((swift_name("TransformIntToLong"))) diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h index 81fdb3d08e6..5e61583e101 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h @@ -302,7 +302,7 @@ __attribute__((swift_name("suspendFunctionChild1"))) * @note This method converts instances of CancellationException to errors. * Other uncaught Kotlin exceptions are fatal. */ -- (void)invokeP1:(NSString *)s completionHandler:(void (^)(NSString * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("invoke(p1:completionHandler:)"))); +- (void)invokeP1:(NSString *)p1 completionHandler:(void (^)(NSString * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("invoke(p1:completionHandler:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1204,8 +1204,8 @@ __attribute__((swift_name("ObjCNameAKt"))) @interface KtObjCNameAKt : KtBase + (NSString *)withUserId:(NSString *)userId __attribute__((swift_name("with(userId:)"))); + (BOOL)supportsFeatures:(BOOL)features __attribute__((swift_name("supports(_:)"))); -+ (NSString *)scanForPeripheralsWithServices:(int32_t)serviceUUIDs options:(NSString *)options __attribute__((swift_name("scanForPeripherals(withServices:options:)"))); -+ (NSString *)registerForConnectionEventsWithOptions:(NSString *)options __attribute__((swift_name("registerForConnectionEvents(options:)"))); ++ (NSString *)scanForPeripheralsWithServices:(int32_t)withServices options:(NSString *)options __attribute__((swift_name("scanForPeripherals(withServices:options:)"))); ++ (NSString *)registerForConnectionEventsWithOptions:(NSString *)withOptions __attribute__((swift_name("registerForConnectionEvents(options:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1221,14 +1221,14 @@ __attribute__((swift_name("MySwiftArray"))) @interface KtMyObjCArray : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)indexOfObject:(int32_t)element __attribute__((swift_name("index(of:)"))); +- (int32_t)indexOfObject:(int32_t)object __attribute__((swift_name("index(of:)"))); @property (readonly) int32_t count __attribute__((swift_name("count"))); @end __attribute__((swift_name("ObjCNameI1"))) @protocol KtObjCNameI1 @required -- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)param __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); +- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)otherParam __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); @property (readonly) int32_t someOtherValue __attribute__((swift_name("someOtherValue"))); @end @@ -1237,7 +1237,7 @@ __attribute__((swift_name("SwiftNameC2"))) @interface KtObjCNameC2 : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)param __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); +- (int32_t)someOtherFunctionReceiver:(int32_t)receiver otherParam:(int32_t)otherParam __attribute__((swift_name("someOtherFunction(receiver:otherParam:)"))); @property int32_t someOtherValue __attribute__((swift_name("someOtherValue"))); @end @@ -1277,7 +1277,7 @@ __attribute__((swift_name("ObjCNameC4"))) @interface KtObjCNameC4 : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (int32_t)fooObjCReceiver:(int32_t)receiver objCParam:(int32_t)param __attribute__((swift_name("foo(objCReceiver:objCParam:)"))); +- (int32_t)fooObjCReceiver:(int32_t)receiver objCParam:(int32_t)objCParam __attribute__((swift_name("foo(objCReceiver:objCParam:)"))); @end __attribute__((objc_subclassing_restricted)) @@ -1311,6 +1311,13 @@ __attribute__((swift_name("ObjCNameSwiftEnum.Companion"))) - (int32_t)foo __attribute__((swift_name("foo()"))); @end +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("ObjCAvoidPreprocessorName"))) +@interface KtObjCAvoidPreprocessorName : KtBase +- (instancetype)initWithTime:(int32_t)time __attribute__((swift_name("init(time:)"))) __attribute__((objc_designated_initializer)); +@property (readonly) int32_t time __attribute__((swift_name("time"))); +@end + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("ObjCNameBKt"))) @interface KtObjCNameBKt : KtBase @@ -2119,16 +2126,16 @@ __attribute__((swift_name("TransformIntToString"))) @interface KtTransformIntToString : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (NSString *)mapValue:(KtInt *)intValue __attribute__((swift_name("map(value:)"))); -- (NSString *)mapIntValue:(int32_t)intValue __attribute__((swift_name("map(intValue:)"))); +- (NSString *)mapValue:(KtInt *)value __attribute__((swift_name("map(value:)"))); +- (NSString *)mapIntValue:(int32_t)value __attribute__((swift_name("map(intValue:)"))); @end __attribute__((swift_name("TransformIntToDecimalString"))) @interface KtTransformIntToDecimalString : KtTransformIntToString - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); -- (NSString *)mapValue:(KtInt *)intValue __attribute__((swift_name("map(value:)"))); -- (NSString *)mapIntValue:(int32_t)intValue __attribute__((swift_name("map(intValue:)"))); +- (NSString *)mapValue:(KtInt *)value __attribute__((swift_name("map(value:)"))); +- (NSString *)mapIntValue:(int32_t)value __attribute__((swift_name("map(intValue:)"))); @end __attribute__((swift_name("TransformIntToLong"))) diff --git a/kotlin-native/backend.native/tests/objcexport/objCName.swift b/kotlin-native/backend.native/tests/objcexport/objCName.swift index 32a8f8d35cc..22cc6351958 100644 --- a/kotlin-native/backend.native/tests/objcexport/objCName.swift +++ b/kotlin-native/backend.native/tests/objcexport/objCName.swift @@ -60,6 +60,11 @@ private func testObjCNameEnum() throws { try assertEquals(actual: ObjCNameSwiftEnum.Companion.shared.foo(), expected: 0) } +private func testObjCAvoidPreprocessorName() throws { + let instance = ObjCAvoidPreprocessorName(time: 42) + try assertEquals(actual: instance.time, expected: 42) +} + class ObjCNameTests : SimpleTestProvider { override init() { super.init() @@ -74,5 +79,6 @@ class ObjCNameTests : SimpleTestProvider { test("TestObjCNameExact", testObjCNameExact) test("TestObjCNameObject", testObjCNameObject) test("TestObjCNameEnum", testObjCNameEnum) + test("TestObjCAvoidPreprocessorName", testObjCAvoidPreprocessorName) } } diff --git a/kotlin-native/backend.native/tests/objcexport/objCNameB.kt b/kotlin-native/backend.native/tests/objcexport/objCNameB.kt index 1c3262132df..4e6e6a934f3 100644 --- a/kotlin-native/backend.native/tests/objcexport/objCNameB.kt +++ b/kotlin-native/backend.native/tests/objcexport/objCNameB.kt @@ -82,3 +82,5 @@ enum class ObjCNameKotlinEnum { fun foo(): Int = 0 } } + +class ObjCAvoidPreprocessorName(@property:ObjCName("time") @ObjCName("time") val __TIME__: Int)