Skip to content

Commit db1c721

Browse files
authored
Merge pull request #73499 from augusto2112/nullptr-source-lock
Add nullptr check in maybeExtractNearestSourceLoc
2 parents 2f361ae + b7bc872 commit db1c721

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/swift/AST/SimpleRequest.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ template<typename T,
100100
typename = typename std::enable_if<
101101
canExtractNearestSourceLoc<T>()>::type>
102102
SourceLoc maybeExtractNearestSourceLoc(const T& value) {
103+
if constexpr (std::is_pointer_v<T>) {
104+
if (value == nullptr) {
105+
return SourceLoc();
106+
}
107+
}
103108
return extractNearestSourceLoc(value);
104109
}
105110

lib/AST/DeclContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,8 @@ bool DeclContext::isAsyncContext() const {
14181418
}
14191419

14201420
SourceLoc swift::extractNearestSourceLoc(const DeclContext *dc) {
1421+
assert(dc && "Expected non-null DeclContext!");
1422+
14211423
switch (dc->getContextKind()) {
14221424
case DeclContextKind::Package:
14231425
case DeclContextKind::Module:

0 commit comments

Comments
 (0)