Fixes issue where cont/break/next stack isn't pushed for expression blocks.

This commit is contained in:
Christoffer Lerno
2021-07-13 16:06:03 +02:00
committed by Christoffer Lerno
parent df311fa8be
commit c94eacd26f
3 changed files with 25 additions and 2 deletions

View File

@@ -4898,7 +4898,13 @@ static inline bool sema_expr_analyse_expr_block(Context *context, Type *to, Expr
Ast **saved_returns = context_push_returns(context);
context->expected_block_type = to;
SCOPE_START_WITH_FLAGS(SCOPE_EXPR_BLOCK)
PUSH_CONTINUE(NULL);
PUSH_BREAK(NULL);
PUSH_NEXT(NULL, NULL);
VECEACH(expr->expr_block.stmts, i)
{
if (!sema_analyse_statement(context, expr->expr_block.stmts[i]))
@@ -4925,7 +4931,11 @@ static inline bool sema_expr_analyse_expr_block(Context *context, Type *to, Expr
goto EXIT;
}
expr_set_type(expr, left_canonical);
EXIT:
EXIT:
POP_BREAKCONT();
POP_NEXT();
SCOPE_END;
context_pop_returns(context, saved_returns);
expr->failable = context->expr_failable_return;

View File

@@ -895,7 +895,7 @@ static bool sema_analyse_break_stmt(Context *context, Ast *statement)
}
else
{
SEMA_ERROR(statement, "'break' is not allowed here.");
SEMA_ERROR(statement, "There is no valid target for 'break', did you make a mistake?");
}
return false;
}

View File

@@ -0,0 +1,13 @@
module fe;
import std::io;
extern func int printf(char *str, ...);
func int main()
{
while(true)
{
return {| break; return 0; |}; // #error: There is no valid target for 'break', did you make a mistake
}
io::println("I didn't return.");
return 0;
}