File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,14 @@ static MetadataResponse getSuperclassForMaybeIncompleteMetadata(
169
169
if (!classMetadata)
170
170
return {_swift_class_getSuperclass (metadata), MetadataState::Complete};
171
171
172
+ #if SWIFT_OBJC_INTEROP
173
+ // Artificial subclasses are not valid type metadata and
174
+ // tryGetCompleteMetadataNonblocking will crash on them. However, they're
175
+ // always fully set up, so we can just skip it and fetch the Subclass field.
176
+ if (classMetadata->isTypeMetadata () && classMetadata->isArtificialSubclass ())
177
+ return {classMetadata->Superclass , MetadataState::Complete};
178
+ #endif
179
+
172
180
MetadataState metadataState;
173
181
if (knownMetadataState)
174
182
metadataState = *knownMetadataState;
Original file line number Diff line number Diff line change @@ -954,4 +954,14 @@ CastsTests.test("Recursive AnyHashable") {
954
954
expectEqual ( s. x, p)
955
955
}
956
956
957
+ #if _runtime(_ObjC)
958
+ CastsTests . test ( " Artificial subclass protocol conformance " ) {
959
+ class SwiftClass : NSObject { }
960
+ let subclass : AnyClass = objc_allocateClassPair ( SwiftClass . self,
961
+ " ArtificialSwiftSubclass " , 0 ) !
962
+ objc_registerClassPair ( subclass)
963
+ expectFalse ( subclass is P . Type )
964
+ }
965
+ #endif
966
+
957
967
runAllTests ( )
You can’t perform that action at this time.
0 commit comments