Skip to content

Commit 7ca7e44

Browse files
committed
[IDE] Fix asstion failure when querying cursor info in defer statement body
If walking into body of defer statement returns nullptr, it indicates *cutting-off* walking. Previously there was wrong assertion where it must be unmodified, non-nullptr return. rdar://problem/41100570
1 parent f2d5f97 commit 7ca7e44

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/IDE/SourceEntityWalker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ std::pair<bool, Stmt *> SemaAnnotator::walkToStmtPre(Stmt *S) {
217217
// walk into the body.
218218
if (auto *FD = DeferS->getTempDecl()) {
219219
auto *RetS = FD->getBody()->walk(*this);
220+
if (!RetS)
221+
return { false, nullptr };
220222
assert(RetS == FD->getBody());
221-
(void)RetS;
222223
}
223224
bool Continue = SEWalker.walkToStmtPost(DeferS);
224225
if (!Continue)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
func foo(x: String) {
2+
defer { _ = x.count }
3+
}
4+
5+
// RUN: %sourcekitd-test -req=cursor -cursor-action -pos=2:15 %s -- %s | %FileCheck %s
6+
// CHECK: source.lang.swift.ref.var.local (1:10-1:11)

0 commit comments

Comments
 (0)