Skip to content

[code-completion] Ensure consumeDecl() does not alter the state of parser. #6110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,7 @@ bool Parser::isStartOfDecl() {
void Parser::consumeDecl(ParserPosition BeginParserPosition,
ParseDeclOptions Flags,
bool IsTopLevel) {
SourceLoc CurrentLoc = Tok.getLoc();
backtrackToPosition(BeginParserPosition);
SourceLoc BeginLoc = Tok.getLoc();
// Consume tokens up to code completion token.
Expand All @@ -1830,6 +1831,9 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition,
CurDeclContext, { BeginLoc, EndLoc },
BeginParserPosition.PreviousLoc);

while (SourceMgr.isBeforeInBuffer(Tok.getLoc(), CurrentLoc))
consumeToken();

if (IsTopLevel) {
// Skip the rest of the file to prevent the parser from constructing the
// AST for it. Forward references are not allowed at the top level.
Expand Down
4 changes: 0 additions & 4 deletions validation-test/IDE/crashers/029-swift-decl-walk.swift

This file was deleted.

2 changes: 2 additions & 0 deletions validation-test/IDE/crashers_fixed/029-swift-decl-walk.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
{var f={{#^A^#}r