ObjCExport: fix replacing Kotlin class methods by Swift extensions
^KT-49937 Fixed
This commit is contained in:
committed by
Space
parent
199edd59f8
commit
4cd60090e0
@@ -958,6 +958,14 @@ __attribute__((swift_name("Kt46431Kt")))
|
||||
+ (id<KtHost>)createAbstractHost __attribute__((swift_name("createAbstractHost()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("KT49937")))
|
||||
@interface KtKT49937 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)description __attribute__((swift_name("description()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("LibraryKt")))
|
||||
@interface KtLibraryKt : KtBase
|
||||
|
||||
@@ -900,6 +900,14 @@ __attribute__((swift_name("Kt46431Kt")))
|
||||
+ (id<KtHost>)createAbstractHost __attribute__((swift_name("createAbstractHost()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("KT49937")))
|
||||
@interface KtKT49937 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)description __attribute__((swift_name("description()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("LibraryKt")))
|
||||
@interface KtLibraryKt : KtBase
|
||||
|
||||
@@ -900,6 +900,14 @@ __attribute__((swift_name("Kt46431Kt")))
|
||||
+ (id<KtHost>)createAbstractHost __attribute__((swift_name("createAbstractHost()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("KT49937")))
|
||||
@interface KtKT49937 : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)description __attribute__((swift_name("description()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("LibraryKt")))
|
||||
@interface KtLibraryKt : KtBase
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt49937
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-49937
|
||||
|
||||
final class KT49937 {
|
||||
override fun toString(): String {
|
||||
return "KT49937"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-49937.
|
||||
|
||||
public extension KT49937 {
|
||||
override var description: String { "KT49937Swift" }
|
||||
}
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: KT49937().description, expected: "KT49937Swift")
|
||||
|
||||
let nsObject: NSObject = KT49937()
|
||||
try assertEquals(actual: nsObject.description, expected: "KT49937Swift")
|
||||
}
|
||||
|
||||
class Kt49937Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -307,15 +307,15 @@ extern "C" void Kotlin_ObjCExport_initializeClass(Class clazz) {
|
||||
for (int i = 0; i < typeAdapter->directAdapterNum; ++i) {
|
||||
const ObjCToKotlinMethodAdapter* adapter = typeAdapter->directAdapters + i;
|
||||
SEL selector = sel_registerName(adapter->selector);
|
||||
BOOL added = class_addMethod(clazz, selector, adapter->imp, adapter->encoding);
|
||||
RuntimeAssert(added, "Unexpected selector clash");
|
||||
class_addMethod(clazz, selector, adapter->imp, adapter->encoding);
|
||||
// The method above may fail if there is a matching Swift/Obj-C extension method for this Kotlin class.
|
||||
// This is pretty much ok, and we shouldn't replace that method with our own.
|
||||
}
|
||||
|
||||
for (int i = 0; i < typeAdapter->classAdapterNum; ++i) {
|
||||
const ObjCToKotlinMethodAdapter* adapter = typeAdapter->classAdapters + i;
|
||||
SEL selector = sel_registerName(adapter->selector);
|
||||
BOOL added = class_addMethod(object_getClass(clazz), selector, adapter->imp, adapter->encoding);
|
||||
RuntimeAssert(added, "Unexpected selector clash");
|
||||
class_addMethod(object_getClass(clazz), selector, adapter->imp, adapter->encoding);
|
||||
}
|
||||
|
||||
if (isClassForPackage) return;
|
||||
|
||||
Reference in New Issue
Block a user