Skip to content

Commit 1395928

Browse files
committed
[IDE] Decrement the global closure discriminator by one before performing the second code completion pass
Otherwise, the closure discriminator will be incremented by one when the closure witht he code completion token is parsed a second time during the second pass, and thus it would receive a different discriminator during the second pass.
1 parent 0dfcf59 commit 1395928

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Parse/Parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ bool CodeCompletionSecondPassRequest::evaluate(
116116
if (!parserState->hasCodeCompletionDelayedDeclState())
117117
return true;
118118

119+
// Decrement the closure discriminator index by one so a top-level closure
120+
// gets the same discriminator as before when being re-parsed in the second
121+
// pass.
122+
parserState->getTopLevelContext().overrideNextClosureDiscriminator(
123+
parserState->getTopLevelContext().claimNextClosureDiscriminator() - 1);
119124
auto state = parserState->takeCodeCompletionDelayedDeclState();
120125
auto &Ctx = SF->getASTContext();
121126

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %sourcekitd-test -req=cursor -pos=4:9 %s -- %s | %FileCheck %s
2+
3+
fileprivate let formatter: DateFormatter = {
4+
let formatter
5+
6+
// CHECK: s:24cursor_in_global_closureXefU_9formatterL_Xevp

0 commit comments

Comments
 (0)