Skip to content

Commit

Permalink
Merge pull request #73499 from augusto2112/nullptr-source-lock
Browse files Browse the repository at this point in the history
Add nullptr check in maybeExtractNearestSourceLoc
  • Loading branch information
augusto2112 committed May 10, 2024
2 parents 2f361ae + b7bc872 commit db1c721
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/swift/AST/SimpleRequest.h
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
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

0 comments on commit db1c721

Please sign in to comment.