parse 'return' without values better

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-18 17:58:51 +02:00
parent 6d84010dc4
commit 701c387dbf

View file

@ -1612,15 +1612,15 @@ static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expre
ast_delete(exp); ast_delete(exp);
return false; return false;
} }
} else {
*out = (ast_expression*)ret; if (!parser_next(parser))
} else if (!parser_next(parser)) { parseerror(parser, "parse error");
parseerror(parser, "expected semicolon");
if (expected->expression.next->expression.vtype != TYPE_VOID) { if (expected->expression.next->expression.vtype != TYPE_VOID) {
parseerror(parser, "return without value"); parseerror(parser, "return without value");
} }
*out = NULL; ret = ast_return_new(exp->expression.node.context, NULL);
} }
*out = (ast_expression*)ret;
return true; return true;
} }
else if (!strcmp(parser_tokval(parser), "if")) else if (!strcmp(parser_tokval(parser), "if"))
@ -1693,6 +1693,7 @@ static ast_block* parser_parse_block(parser_t *parser)
break; break;
if (!parser_parse_statement(parser, block, &expr)) { if (!parser_parse_statement(parser, block, &expr)) {
parseerror(parser, "parse error");
ast_block_delete(block); ast_block_delete(block);
block = NULL; block = NULL;
goto cleanup; goto cleanup;