Skip to content

Commit da1c5c9

Browse files
committed
Parse: Fix repeat/while error recovery path
We were creating an ErrorExpr whose source range overlaps with the following statement, which is now flagged by ASTScope.
1 parent faae25a commit da1c5c9

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6000,7 +6000,7 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
60006000
// up in Decls to be returned to caller.
60016001
if (topLevelDecl) {
60026002
PBD->setDeclContext(topLevelDecl);
6003-
auto range = PBD->getSourceRange();
6003+
auto range = PBD->getSourceRangeIncludingAttrs();
60046004
topLevelDecl->setBody(BraceStmt::create(Context, range.Start,
60056005
ASTNode(PBD), range.End, true));
60066006
Decls.insert(Decls.begin()+NumDeclsInResult, topLevelDecl);

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,9 +1876,8 @@ ParserResult<Stmt> Parser::parseStmtRepeat(LabeledStmtInfo labelInfo) {
18761876

18771877
ParserResult<Expr> condition;
18781878
if (Tok.is(tok::l_brace)) {
1879-
SourceLoc lbraceLoc = Tok.getLoc();
18801879
diagnose(whileLoc, diag::missing_condition_after_while);
1881-
condition = makeParserErrorResult(new (Context) ErrorExpr(lbraceLoc));
1880+
condition = makeParserErrorResult(new (Context) ErrorExpr(whileLoc));
18821881
} else {
18831882
condition = parseExpr(diag::expected_expr_repeat_while);
18841883
status |= condition;

0 commit comments

Comments
 (0)