Skip to content

Commit 70499ed

Browse files
committed
Add diagnostics for semicolon at the end of while body
This change introduce diagnostics when there is a semicolon at the end of the while loop body: ```cpp i := 0; while i* < container.size() next i++ { std::cout << container[i] << std::endl; }; ``` generates: ``` error: while loop body shall not end with a semicolon (at ';') ```
1 parent a8dd408 commit 70499ed

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

source/parse.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,6 +4208,10 @@ class parser
42084208
if (!handle_logical_expression ()) { return {}; }
42094209
if (!handle_optional_next_clause()) { return {}; }
42104210
if (!handle_compound_statement ()) { return {}; }
4211+
if (!done() && curr().type() == lexeme::Semicolon) {
4212+
error("a loop body may not be followed by a semicolon (empty statements are not allowed)");
4213+
return {};
4214+
}
42114215
return n;
42124216
}
42134217

0 commit comments

Comments
 (0)