mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 18:02:02 +00:00
Disallow labelled branches in defer - fix #3960
This commit is contained in:
@@ -199,6 +199,9 @@ gb_internal bool check_has_break(Ast *stmt, String const &label, bool implicit)
|
||||
}
|
||||
break;
|
||||
|
||||
case Ast_DeferStmt:
|
||||
return check_has_break(stmt->DeferStmt.stmt, label, implicit);
|
||||
|
||||
case Ast_BlockStmt:
|
||||
return check_has_break_list(stmt->BlockStmt.stmts, label, implicit);
|
||||
|
||||
@@ -2706,6 +2709,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
error(bs->label, "A branch statement's label name must be an identifier");
|
||||
return;
|
||||
}
|
||||
|
||||
Ast *ident = bs->label;
|
||||
String name = ident->Ident.token.string;
|
||||
Operand o = {};
|
||||
@@ -2737,6 +2741,10 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (ctx->in_defer) {
|
||||
error(bs->label, "A labelled '%.*s' cannot be used within a 'defer'", LIT(token.string));
|
||||
}
|
||||
}
|
||||
|
||||
case_end;
|
||||
|
||||
Reference in New Issue
Block a user