Skip to content

Commit 412a0f1

Browse files
authored
Merge pull request #28079 from davezarzycki/pr28079
[Parser] Track missing right brace correctly
2 parents 1c73565 + 4927607 commit 412a0f1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,8 +2755,11 @@ ParserResult<Expr> Parser::parseExprClosure() {
27552755

27562756
// Parse the closing '}'.
27572757
SourceLoc rightBrace;
2758-
parseMatchingToken(tok::r_brace, rightBrace, diag::expected_closure_rbrace,
2759-
leftBrace);
2758+
bool missingRBrace = parseMatchingToken(tok::r_brace, rightBrace,
2759+
diag::expected_closure_rbrace,
2760+
leftBrace);
2761+
if (missingRBrace)
2762+
Status.setIsParseError();
27602763

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

0 commit comments

Comments
 (0)