Skip to content

Commit 54e8527

Browse files
authored
[code-completion] Ensure consumeDecl() does not alter the state of parser. (#6110)
This also fixes IDE/crashers/029-swift-decl-walk.swift.
1 parent 2192775 commit 54e8527

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@ bool Parser::isStartOfDecl() {
18151815
void Parser::consumeDecl(ParserPosition BeginParserPosition,
18161816
ParseDeclOptions Flags,
18171817
bool IsTopLevel) {
1818+
SourceLoc CurrentLoc = Tok.getLoc();
18181819
backtrackToPosition(BeginParserPosition);
18191820
SourceLoc BeginLoc = Tok.getLoc();
18201821
// Consume tokens up to code completion token.
@@ -1830,6 +1831,9 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition,
18301831
CurDeclContext, { BeginLoc, EndLoc },
18311832
BeginParserPosition.PreviousLoc);
18321833

1834+
while (SourceMgr.isBeforeInBuffer(Tok.getLoc(), CurrentLoc))
1835+
consumeToken();
1836+
18331837
if (IsTopLevel) {
18341838
// Skip the rest of the file to prevent the parser from constructing the
18351839
// AST for it. Forward references are not allowed at the top level.

validation-test/IDE/crashers/029-swift-decl-walk.swift

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
{var f={{#^A^#}r

0 commit comments

Comments
 (0)