Skip to content

Commit 53994d1

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 56024b3 commit 53994d1

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
@@ -7383,7 +7383,8 @@ Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
73837383
// In implicit getter, if a CC token is the first token after '{', it might
73847384
// be a start of an accessor block. Perform special completion for that.
73857385
if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
7386-
if (peekToken().is(tok::code_complete) && accessor->isImplicitGetter()) {
7386+
if (CodeCompletion && peekToken().is(tok::code_complete) &&
7387+
accessor->isImplicitGetter()) {
73877388
SourceLoc LBraceLoc, RBraceLoc;
73887389
LBraceLoc = consumeToken(tok::l_brace);
73897390
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)