Skip to content

Commit 369e7d3

Browse files
committed
[Reflection] Make TypeRefVisitor robust to NULL typerefs and unknown kinds.
These shouldn't happen, but we may encounter bad data which results in a NULL typeref pointer, or a bogus kind value. rdar://103111816 rdar://103105744
1 parent 5b8cd58 commit 369e7d3

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)