mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fixes issue where cont/break/next stack isn't pushed for expression blocks.
This commit is contained in:
committed by
Christoffer Lerno
parent
df311fa8be
commit
c94eacd26f
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
13
test/test_suite/expression_block/expression_block_break.c3
Normal file
13
test/test_suite/expression_block/expression_block_break.c3
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user