aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2017-04-02 13:47:23 -0700
committerJosh Wolfe <thejoshwolfe@gmail.com>2017-04-02 13:47:23 -0700
commita33be6fc9906e010a44087dc2b7143717d875505 (patch)
tree94053d6b0248f78ea90e26ffaa6917627c5bd471 /src
parent8d03d666af1b8b14e6702c2502846e3c1a79e9da (diff)
downloadzig-a33be6fc9906e010a44087dc2b7143717d875505.tar.gz
zig-a33be6fc9906e010a44087dc2b7143717d875505.zip
defer without a block body requires a following semicolon
Diffstat (limited to 'src')
-rw-r--r--src/parser.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index a63464dbe5..0c02eaef2a 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -2118,6 +2118,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
bool need_implicit_final_void_statement = false;
bool semicolon_expected = true;
if (statement_node) {
+ // label
semicolon_expected = false;
// if a label is the last thing in a block, add a void statement.
need_implicit_final_void_statement = true;
@@ -2126,19 +2127,29 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
if (!statement_node) {
statement_node = ast_parse_defer_expr(pc, token_index);
if (statement_node) {
- // don't let defer be the last statement in a block
- need_implicit_final_void_statement = true;
- } else {
- statement_node = ast_parse_block_expr(pc, token_index, false);
- }
- if (statement_node) {
- if (statement_has_block_body(statement_node))
+ // defer
+ if (statement_has_block_body(statement_node)) {
+ // don't let defer be the last statement in a block
+ need_implicit_final_void_statement = true;
semicolon_expected = false;
+ } else {
+ // defer without a block body requires a semicolon
+ Token *token = &pc->tokens->at(*token_index);
+ ast_expect_token(pc, token, TokenIdSemicolon);
+ }
} else {
- statement_node = ast_parse_expression(pc, token_index, false);
- if (!statement_node) {
- // final semicolon means add a void statement.
- need_implicit_final_void_statement = true;
+ statement_node = ast_parse_block_expr(pc, token_index, false);
+ if (statement_node) {
+ // block expr
+ if (statement_has_block_body(statement_node))
+ semicolon_expected = false;
+ } else {
+ statement_node = ast_parse_expression(pc, token_index, false);
+ if (!statement_node) {
+ // no statement.
+ // final semicolon means add a void statement.
+ need_implicit_final_void_statement = true;
+ }
}
}
}