Skip to content

[Parser] Track missing right brace correctly #28079

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 1 commit into from
Nov 5, 2019
Merged
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/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2755,8 +2755,11 @@ ParserResult<Expr> Parser::parseExprClosure() {

// Parse the closing '}'.
SourceLoc rightBrace;
parseMatchingToken(tok::r_brace, rightBrace, diag::expected_closure_rbrace,
leftBrace);
bool missingRBrace = parseMatchingToken(tok::r_brace, rightBrace,
diag::expected_closure_rbrace,
leftBrace);
if (missingRBrace)
Status.setIsParseError();

// If we didn't have any parameters, create a parameter list from the
// anonymous closure arguments.
Expand Down Expand Up @@ -2784,7 +2787,8 @@ ParserResult<Expr> Parser::parseExprClosure() {
// may be incomplete and the type mismatch in return statement will just
// confuse the type checker.
bool hasSingleExpressionBody = false;
if (!Status.hasCodeCompletion() && bodyElements.size() == 1) {
if (!missingRBrace && !Status.hasCodeCompletion() &&
bodyElements.size() == 1) {
// If the closure's only body element is a single return statement,
// use that instead of creating a new wrapping return expression.
Expr *returnExpr = nullptr;
Expand Down