Skip to content

Commit 5fa686b

Browse files
committed
Add nullptr check in maybeExtractNearestSourceLoc
For templated types which are pointers, check if the pointer is null in maybeExtractNearestSourceLoc. rdar://127251788
1 parent e805679 commit 5fa686b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

include/swift/AST/SimpleRequest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ 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();
103106
return extractNearestSourceLoc(value);
104107
}
105108

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)