Skip to content

Commit 7bcf1fc

Browse files
authored
Merge pull request #62483 from mikeash/robustify-typeref-visitor
[Reflection] Make TypeRefVisitor robust to NULL typerefs and unknown kinds.
2 parents 48f63c5 + 369e7d3 commit 7bcf1fc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

include/swift/Reflection/TypeRef.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,10 @@ class TypeRefVisitor {
10241024
public:
10251025

10261026
RetTy visit(const TypeRef *typeRef, Args... args) {
1027+
// We shouldn't get a NULL typeRef, but handle it gracefully if we do.
1028+
if (!typeRef)
1029+
return RetTy();
1030+
10271031
switch (typeRef->getKind()) {
10281032
#define TYPEREF(Id, Parent) \
10291033
case TypeRefKind::Id: \
@@ -1033,7 +1037,9 @@ class TypeRefVisitor {
10331037
#include "swift/Reflection/TypeRefs.def"
10341038
}
10351039

1036-
swift_unreachable("Unhandled TypeRefKind in switch.");
1040+
// We shouldn't get an unknown kind, but bad data might result in an unknown
1041+
// value showing up here. Handle it gracefully when that happens.
1042+
return RetTy();
10371043
}
10381044
};
10391045

0 commit comments

Comments
 (0)