Skip to content

Commit 0cff498

Browse files
committed
[Reflection] Use getClassObject() when testing for ObjCness rather than blindly casting to ClassMetada, which turns out to be completely incorrect.
1 parent fa2ea03 commit 0cff498

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/public/runtime/ReflectionMirror.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ AnyReturn subscript(intptr_t i, const char **outName,
514514

515515

516516
template<typename F>
517-
auto call(OpaqueValue *passedValue, const Metadata *T, const Metadata *passedType, const F &f)
518-
-> decltype(f(nullptr))
517+
auto call(OpaqueValue *passedValue, const Metadata *T, const Metadata *passedType,
518+
const F &f) -> decltype(f(nullptr))
519519
{
520520
const Metadata *type;
521521
OpaqueValue *value;
@@ -548,7 +548,9 @@ auto call(OpaqueValue *passedValue, const Metadata *T, const Metadata *passedTyp
548548

549549
#if SWIFT_OBJC_INTEROP
550550
// If this is a pure ObjC class, reflect it using ObjC's runtime facilities.
551-
if (!static_cast<const ClassMetadata*>(passedType)->isTypeMetadata()) {
551+
// ForeignClass (e.g. CF classes) manifests as a NULL class object.
552+
auto classObject = passedType->getClassObject();
553+
if (classObject == nullptr || !classObject->isTypeMetadata()) {
552554
ObjCClassImpl impl;
553555
return call(&impl);
554556
}

0 commit comments

Comments
 (0)