Skip to content

[Reflection] Make TypeRefVisitor robust to NULL typerefs and unknown kinds. #62483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/swift/Reflection/TypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,10 @@ class TypeRefVisitor {
public:

RetTy visit(const TypeRef *typeRef, Args... args) {
// We shouldn't get a NULL typeRef, but handle it gracefully if we do.
if (!typeRef)
return RetTy();

switch (typeRef->getKind()) {
#define TYPEREF(Id, Parent) \
case TypeRefKind::Id: \
Expand All @@ -1033,7 +1037,9 @@ class TypeRefVisitor {
#include "swift/Reflection/TypeRefs.def"
}

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

Expand Down