Skip to content

Commit

Permalink
Fix diagnosis location for missing while after repeat body
Browse files Browse the repository at this point in the history
Also cleaned up unnecessary body.isNonNull() check here. The code just
above already constructs a synthetic empty brace stmt for the body if
it didn’t have a real one.
  • Loading branch information
gregomni committed Jan 15, 2016
1 parent 007db33 commit 854a763
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/Parse/ParseStmt.cpp
Expand Up @@ -1812,10 +1812,8 @@ ParserResult<Stmt> Parser::parseStmtRepeat(LabeledStmtInfo labelInfo) {
SourceLoc whileLoc;

if (!consumeIf(tok::kw_while, whileLoc)) {
diagnose(whileLoc, diag::expected_while_after_repeat_body);
if (body.isNonNull())
return body;
return makeParserError();
diagnose(body.getPtrOrNull()->getEndLoc(), diag::expected_while_after_repeat_body);
return body;
}

ParserResult<Expr> condition;
Expand Down
6 changes: 6 additions & 0 deletions test/Parse/recovery.swift
Expand Up @@ -131,6 +131,12 @@ func missingControllingExprInRepeatWhile() {
} while { true }() // expected-error{{missing condition in a 'while' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{10-10=;}}
}

// SR-165
func missingWhileInRepeat() {
repeat {
} // expected-error {{expected 'while' after body of 'repeat' statement}}
}

// expected-note @+1 {{in call to function 'acceptsClosure'}}
func acceptsClosure<T>(t: T) -> Bool { return true }

Expand Down
2 changes: 1 addition & 1 deletion test/stmt/statements.swift
Expand Up @@ -266,7 +266,7 @@ func RepeatWhileStmt1() {
}

func RepeatWhileStmt2() {
repeat // expected-error {{expected '{' after 'repeat'}}
repeat // expected-error {{expected '{' after 'repeat'}} expected-error {{expected 'while' after body of 'repeat' statement}}
}

func RepeatWhileStmt4() {
Expand Down

0 comments on commit 854a763

Please sign in to comment.