Native: add flag that disables ObjC method name mangling for methods in different Kotlin Interfaces (#5070)
This commit is contained in:
@@ -657,6 +657,53 @@ __attribute__((swift_name("TestGH3992.B")))
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("InterfaceNameManglingI1")))
|
||||
@protocol KtInterfaceNameManglingI1
|
||||
@required
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInI1 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI1()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInI2 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI2()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInBoth __attribute__((swift_name("interfaceClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("InterfaceNameManglingI2")))
|
||||
@protocol KtInterfaceNameManglingI2
|
||||
@required
|
||||
- (id)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInI1 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI1()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInI2 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI2()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInBoth __attribute__((swift_name("interfaceClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) id clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceNameManglingC1")))
|
||||
@interface KtInterfaceNameManglingC1 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
@property (readonly) NSString *clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceNameManglingC2")))
|
||||
@interface KtInterfaceNameManglingC2 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceMethodNameManglingKt")))
|
||||
@interface KtInterfaceMethodNameManglingKt : KtBase
|
||||
+ (id<KtInterfaceNameManglingI1>)i1 __attribute__((swift_name("i1()")));
|
||||
+ (id<KtInterfaceNameManglingI2>)i2 __attribute__((swift_name("i2()")));
|
||||
+ (KtInterfaceNameManglingC1 *)o1 __attribute__((swift_name("o1()")));
|
||||
+ (KtInterfaceNameManglingC2 *)o2 __attribute__((swift_name("o2()")));
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
* Summary class [KDocExport].
|
||||
|
||||
@@ -657,6 +657,53 @@ __attribute__((swift_name("TestGH3992.B")))
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("InterfaceNameManglingI1")))
|
||||
@protocol KtInterfaceNameManglingI1
|
||||
@required
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInI1 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI1()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInI2 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI2()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInBoth __attribute__((swift_name("interfaceClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("InterfaceNameManglingI2")))
|
||||
@protocol KtInterfaceNameManglingI2
|
||||
@required
|
||||
- (id)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInI1 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI1()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInI2 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI2()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInBoth __attribute__((swift_name("interfaceClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) id clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceNameManglingC1")))
|
||||
@interface KtInterfaceNameManglingC1 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
@property (readonly) NSString *clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceNameManglingC2")))
|
||||
@interface KtInterfaceNameManglingC2 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceMethodNameManglingKt")))
|
||||
@interface KtInterfaceMethodNameManglingKt : KtBase
|
||||
+ (id<KtInterfaceNameManglingI1>)i1 __attribute__((swift_name("i1()")));
|
||||
+ (id<KtInterfaceNameManglingI2>)i2 __attribute__((swift_name("i2()")));
|
||||
+ (KtInterfaceNameManglingC1 *)o1 __attribute__((swift_name("o1()")));
|
||||
+ (KtInterfaceNameManglingC2 *)o2 __attribute__((swift_name("o2()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("KDocExport")))
|
||||
@interface KtKDocExport : KtBase
|
||||
|
||||
@@ -657,6 +657,53 @@ __attribute__((swift_name("TestGH3992.B")))
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("InterfaceNameManglingI1")))
|
||||
@protocol KtInterfaceNameManglingI1
|
||||
@required
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInI1 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI1()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInI2 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI2()")));
|
||||
- (int32_t)interfaceClashingMethodWithObjCNameInBoth __attribute__((swift_name("interfaceClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("InterfaceNameManglingI2")))
|
||||
@protocol KtInterfaceNameManglingI2
|
||||
@required
|
||||
- (id)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInI1 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI1()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInI2 __attribute__((swift_name("interfaceClashingMethodWithObjCNameInI2()")));
|
||||
- (id)interfaceClashingMethodWithObjCNameInBoth __attribute__((swift_name("interfaceClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) id clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceNameManglingC1")))
|
||||
@interface KtInterfaceNameManglingC1 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
@property (readonly) NSString *clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceNameManglingC2")))
|
||||
@interface KtInterfaceNameManglingC2 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("InterfaceMethodNameManglingKt")))
|
||||
@interface KtInterfaceMethodNameManglingKt : KtBase
|
||||
+ (id<KtInterfaceNameManglingI1>)i1 __attribute__((swift_name("i1()")));
|
||||
+ (id<KtInterfaceNameManglingI2>)i2 __attribute__((swift_name("i2()")));
|
||||
+ (KtInterfaceNameManglingC1 *)o1 __attribute__((swift_name("o1()")));
|
||||
+ (KtInterfaceNameManglingC2 *)o2 __attribute__((swift_name("o2()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("KDocExport")))
|
||||
@interface KtKDocExport : KtBase
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalObjCName::class)
|
||||
|
||||
package objcNameMangling
|
||||
|
||||
interface InterfaceNameManglingI1 {
|
||||
val clashingProperty: Int
|
||||
|
||||
fun clashingMethod(): Int
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInI1")
|
||||
fun clashingMethodWithObjCNameInI1(): Int
|
||||
|
||||
fun interfaceClashingMethodWithObjCNameInI2(): Int
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInBoth")
|
||||
fun clashingMethodWithObjCNameInBoth(): Int
|
||||
}
|
||||
|
||||
fun i1() = object : InterfaceNameManglingI1 {
|
||||
override val clashingProperty: Int
|
||||
get() = 1
|
||||
|
||||
override fun clashingMethod(): Int = 2
|
||||
|
||||
override fun clashingMethodWithObjCNameInI1(): Int = 3
|
||||
|
||||
override fun interfaceClashingMethodWithObjCNameInI2(): Int = 4
|
||||
|
||||
override fun clashingMethodWithObjCNameInBoth(): Int = 5
|
||||
}
|
||||
|
||||
interface InterfaceNameManglingI2 {
|
||||
val clashingProperty: Any
|
||||
|
||||
fun clashingMethod(): Any
|
||||
|
||||
fun interfaceClashingMethodWithObjCNameInI1(): Any
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInI2")
|
||||
fun clashingMethodWithObjCNameInI2(): Any
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInBoth")
|
||||
fun clashingMethodWithObjCNameInBoth(): Any
|
||||
}
|
||||
|
||||
fun i2() = object : InterfaceNameManglingI2 {
|
||||
override val clashingProperty: Any
|
||||
get() = "one"
|
||||
|
||||
override fun clashingMethod(): Any = "two"
|
||||
|
||||
override fun interfaceClashingMethodWithObjCNameInI1(): Any = "three"
|
||||
|
||||
override fun clashingMethodWithObjCNameInI2(): Any = "four"
|
||||
|
||||
override fun clashingMethodWithObjCNameInBoth(): Any = "five"
|
||||
}
|
||||
|
||||
class InterfaceNameManglingC1 {
|
||||
val clashingProperty: String = "one"
|
||||
|
||||
fun clashingMethod(): String = "two"
|
||||
}
|
||||
|
||||
final class InterfaceNameManglingC2 {
|
||||
val clashingProperty: Int = 1
|
||||
|
||||
fun clashingMethod(): Int = 2
|
||||
}
|
||||
|
||||
fun o1() = InterfaceNameManglingC1()
|
||||
|
||||
fun o2() = InterfaceNameManglingC2()
|
||||
@@ -0,0 +1,35 @@
|
||||
import Kt
|
||||
|
||||
private func test1() throws {
|
||||
let i1 = InterfaceMethodNameManglingKt.i1()
|
||||
let i2 = InterfaceMethodNameManglingKt.i2()
|
||||
let o1 = InterfaceMethodNameManglingKt.o1()
|
||||
let o2 = InterfaceMethodNameManglingKt.o2()
|
||||
|
||||
#if DISABLE_MEMBER_NAME_MANGLING || DISABLE_INTERFACE_METHOD_NAME_MANGLING
|
||||
try assertEquals(actual: i1.clashingProperty, expected: 1)
|
||||
try assertEquals(actual: i1.clashingMethod(), expected: 2)
|
||||
try assertEquals(actual: i1.interfaceClashingMethodWithObjCNameInI1(), expected: 3)
|
||||
try assertEquals(actual: i1.interfaceClashingMethodWithObjCNameInI2(), expected: 4)
|
||||
try assertEquals(actual: i1.interfaceClashingMethodWithObjCNameInBoth(), expected: 5)
|
||||
|
||||
try assertEquals(actual: i2.clashingProperty as! String, expected: "one")
|
||||
try assertEquals(actual: i2.clashingMethod() as! String, expected: "two")
|
||||
try assertEquals(actual: i2.interfaceClashingMethodWithObjCNameInI1() as! String, expected: "three")
|
||||
try assertEquals(actual: i2.interfaceClashingMethodWithObjCNameInI2() as! String, expected: "four")
|
||||
try assertEquals(actual: i2.interfaceClashingMethodWithObjCNameInBoth() as! String, expected: "five")
|
||||
|
||||
try assertEquals(actual: o1.clashingProperty, expected: "one")
|
||||
try assertEquals(actual: o1.clashingMethod(), expected: "two")
|
||||
#endif
|
||||
try assertEquals(actual: o2.clashingProperty, expected: 1)
|
||||
try assertEquals(actual: o2.clashingMethod(), expected: 2)
|
||||
}
|
||||
|
||||
class InterfaceMethodNameManglingTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ private func test1() throws {
|
||||
let i1 = SwiftNameManglingKt.i1()
|
||||
let i2 = SwiftNameManglingKt.i2()
|
||||
|
||||
#if DISABLE_MEMBER_NAME_MANGLING
|
||||
#if DISABLE_MEMBER_NAME_MANGLING || DISABLE_INTERFACE_METHOD_NAME_MANGLING
|
||||
try assertEquals(actual: i1.clashingProperty, expected: 1)
|
||||
try assertEquals(actual: i1.clashingMethod(), expected: 2)
|
||||
try assertEquals(actual: i1.swiftClashingMethodWithObjCNameInI1(), expected: 3)
|
||||
|
||||
@@ -727,7 +727,7 @@ func testClashes() throws {
|
||||
|
||||
try assertEquals(actual: 1, expected: test1.clashingProperty)
|
||||
|
||||
#if !DISABLE_MEMBER_NAME_MANGLING
|
||||
#if !DISABLE_MEMBER_NAME_MANGLING && !DISABLE_INTERFACE_METHOD_NAME_MANGLING
|
||||
try assertEquals(actual: 1, expected: test2.clashingProperty_ as! Int32)
|
||||
try assertEquals(actual: 2, expected: test2.clashingProperty__ as! Int32)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user