Skip to content

Commit 0f809e4

Browse files
authored
Don't use _getSuperclass() from the Swift runtime. (swiftlang#1237)
To determine if a class is a subclass of another, we can use `T.self is U.Type` in an implicitly-opened existential context. Prior to the Swift 6 language mode, type existentials weren't openable, so we had to recursively call a runtime function to check this. That's no longer a concern for us. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 880c37b commit 0f809e4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Sources/Testing/Parameterization/TypeInfo.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,10 @@ extension TypeInfo {
360360
/// - Returns: Whether `subclass` is a subclass of, or is equal to,
361361
/// `superclass`.
362362
func isClass(_ subclass: AnyClass, subclassOf superclass: AnyClass) -> Bool {
363-
if subclass == superclass {
364-
true
365-
} else if let subclassImmediateSuperclass = _getSuperclass(subclass) {
366-
isClass(subclassImmediateSuperclass, subclassOf: superclass)
367-
} else {
368-
false
363+
func open<T, U>(_: T.Type, _: U.Type) -> Bool where T: AnyObject, U: AnyObject {
364+
T.self is U.Type
369365
}
366+
return open(subclass, superclass)
370367
}
371368

372369
// MARK: - CustomStringConvertible, CustomDebugStringConvertible, CustomTestStringConvertible

0 commit comments

Comments
 (0)