Skip to content
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: 6 additions & 4 deletions lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,15 +1770,17 @@ static bool isStmtForCStyle(Parser &P) {
auto HasLParen = P.consumeIf(tok::l_paren);

// Skip until we see ';', or something that ends control part.
while (P.Tok.isNot(tok::eof, tok::kw_in, tok::semi, tok::l_brace,
tok::r_brace, tok::r_paren) && !P.isStartOfStmt()) {
while (true) {
if (P.Tok.isAny(tok::eof, tok::kw_in, tok::l_brace, tok::r_brace,
tok::r_paren) || P.isStartOfStmt())
return false;
// If we saw newline before ';', consider it is a foreach statement.
if (!HasLParen && P.Tok.isAtStartOfLine())
return false;
if (P.Tok.is(tok::semi))
return true;
P.skipSingle();
}

return P.Tok.is(tok::semi);
}

///
Expand Down
3 changes: 3 additions & 0 deletions test/Parse/recovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func missingControllingExprInForEach() {
let key = "\(name)"
}
}

for // expected-error {{expected pattern}} expected-error {{Sequence expression for for-each loop}}
; // expected-error {{expected '{' to start the body of for-each loop}}
}

func missingControllingExprInSwitch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// REQUIRES: asserts
// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
{for
;