Skip to content

Add nullptr check in maybeExtractNearestSourceLoc #73499

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
May 10, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions include/swift/AST/SimpleRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ template<typename T,
typename = typename std::enable_if<
canExtractNearestSourceLoc<T>()>::type>
SourceLoc maybeExtractNearestSourceLoc(const T& value) {
if constexpr (std::is_pointer_v<T>) {
if (value == nullptr) {
return SourceLoc();
}
}
return extractNearestSourceLoc(value);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,8 @@ bool DeclContext::isAsyncContext() const {
}

SourceLoc swift::extractNearestSourceLoc(const DeclContext *dc) {
assert(dc && "Expected non-null DeclContext!");

switch (dc->getContextKind()) {
case DeclContextKind::Package:
case DeclContextKind::Module:
Expand Down