Skip to content

[CodeCompletion] Parse multiple catch clauses if the do body contains the code completion token #72910

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
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
10 changes: 7 additions & 3 deletions lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2202,16 +2202,20 @@ ParserResult<Stmt> Parser::parseStmtDo(LabeledStmtInfo labelInfo,
if (Tok.is(tok::kw_catch)) {
// Parse 'catch' clauses
SmallVector<CaseStmt *, 4> allClauses;
ParserStatus catchClausesStatus;
do {
ParserResult<CaseStmt> clause = parseStmtCatch();
status |= clause;
if (status.hasCodeCompletion() && clause.isNull())
catchClausesStatus |= clause;
if (catchClausesStatus.hasCodeCompletion() && clause.isNull()) {
status |= catchClausesStatus;
return makeParserResult<Stmt>(status, nullptr);
}

// parseStmtCatch promises to return non-null unless we are
// completing inside the catch's pattern.
allClauses.push_back(clause.get());
} while (Tok.is(tok::kw_catch) && !status.hasCodeCompletion());
} while (Tok.is(tok::kw_catch) && !catchClausesStatus.hasCodeCompletion());
status |= catchClausesStatus;

// Recover from all of the clauses failing to parse by returning a
// normal do-statement.
Expand Down
15 changes: 15 additions & 0 deletions test/IDE/complete_do_with_multiple_catch_in_closure.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %batch-code-completion

func takeClosure(_ body: () -> Void) {}

func test() {
let myVar = 1
takeClosure {
do {
#^COMPLETE^#
// COMPLETE: Decl[LocalVar]/Local: myVar[#Int#];
} catch let error as Int {
} catch let error {
}
}
}