[Swift Export]: KT-69469: Allow objc/swift-exported types to return a refined wrapper type when such is available as associated object
diff --git a/kotlin-native/runtime/src/objc/cpp/ObjCExportClasses.mm b/kotlin-native/runtime/src/objc/cpp/ObjCExportClasses.mm
index 61f1173..b8d5695 100644
--- a/kotlin-native/runtime/src/objc/cpp/ObjCExportClasses.mm
+++ b/kotlin-native/runtime/src/objc/cpp/ObjCExportClasses.mm
@@ -193,7 +193,9 @@
return [self retain];
}
+// TODO: KT-69636 - obtain the most appropriate wrapper type and replace self with the instance of it
- (instancetype)initWithExternalRCRef:(uintptr_t)ref {
+
kotlin::CalledFromNativeGuard guard;
RuntimeAssert(kotlin::compiler::swiftExport(), "Must be used in Swift Export only");
@@ -214,7 +216,11 @@
}
// Kotlin object did have an associated object attached.
- RuntimeAssert([old class] == [self class], "Object %p had associated object of type %p but we try to init with %p", obj, [old class], [self class]);
+ RuntimeAssert(
+ [[old class] isSubclassOfClass:[self class]],
+ "Object %p had associated object of type %s but we try to init with %s",
+ obj, class_getName([old class]), class_getName([self class])
+ );
// Make self point to that object.
KotlinBase* retiredSelf = self;