This commit is contained in:
gingerBill
2024-03-16 22:12:17 +00:00
parent 04f0fbf23a
commit 3875fb08e8
3 changed files with 10 additions and 0 deletions

View File

@@ -8405,6 +8405,7 @@ gb_internal ExprKind check_or_branch_expr(CheckerContext *c, Operand *o, Ast *no
switch (be->token.kind) {
case Token_or_break:
node->viral_state_flags |= ViralStateFlag_ContainsOrBreak;
if ((c->stmt_flags & Stmt_BreakAllowed) == 0 && label == nullptr) {
error(be->token, "'%.*s' only allowed in non-inline loops or 'switch' statements", LIT(name));
}
@@ -10254,6 +10255,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast
case_end;
case_ast_node(re, OrReturnExpr, node);
node->viral_state_flags |= ViralStateFlag_ContainsOrReturn;
return check_or_return_expr(c, o, node, type_hint);
case_end;

View File

@@ -221,6 +221,12 @@ gb_internal bool check_has_break(Ast *stmt, String const &label, bool implicit)
return true;
}
break;
case Ast_ExprStmt:
if (stmt->ExprStmt.expr->viral_state_flags & ViralStateFlag_ContainsOrBreak) {
return true;
}
break;
}
return false;

View File

@@ -310,6 +310,8 @@ enum StateFlag : u8 {
enum ViralStateFlag : u8 {
ViralStateFlag_ContainsDeferredProcedure = 1<<0,
ViralStateFlag_ContainsOrBreak = 1<<1,
ViralStateFlag_ContainsOrReturn = 1<<2,
};