Skip to content

Commit 9bc8774

Browse files
committed
[Parse] Fix code completion crash when avoiding skipping
Fix a crash that could occur when performing completion at the start of an accessor body. Previously we assumed `CodeCompletion` would never be null due to function body skipping in the first pass of code completion. However with the introduction of the ability to avoid skipping in certain cases, it might be now be null if we need to avoid skipping. Found by the stress tester. rdar://95772803
1 parent 983166f commit 9bc8774

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7374,7 +7374,8 @@ Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
73747374
// In implicit getter, if a CC token is the first token after '{', it might
73757375
// be a start of an accessor block. Perform special completion for that.
73767376
if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
7377-
if (peekToken().is(tok::code_complete) && accessor->isImplicitGetter()) {
7377+
if (CodeCompletion && peekToken().is(tok::code_complete) &&
7378+
accessor->isImplicitGetter()) {
73787379
SourceLoc LBraceLoc, RBraceLoc;
73797380
LBraceLoc = consumeToken(tok::l_brace);
73807381
auto *CCE = new (Context) CodeCompletionExpr(Tok.getLoc());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
var foo: Double { 1 / 2 }
3+
var bar: Regex<Substring> { /x/ }
4+
var baz: Regex<Substring> { / x/ }
5+
var qux: Regex<Substring> { / x}/ }
6+
7+
// Check that we are not crashing
8+
// RUN: %sourcekitd-test \
9+
// RUN: -req=complete -pos=2:18 %s -- -enable-bare-slash-regex %s == \
10+
// RUN: -req=complete -pos=3:28 %s -- -enable-bare-slash-regex %s == \
11+
// RUN: -req=complete -pos=4:28 %s -- -enable-bare-slash-regex %s == \
12+
// RUN: -req=complete -pos=5:28 %s -- -enable-bare-slash-regex %s
13+
14+
// REQUIRES: swift_in_compiler

0 commit comments

Comments
 (0)