Browse Source

Forbid labelled or-branch expressions within `defer`

Feoramund 11 months ago
parent
commit
acbf5c8d97
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/check_expr.cpp

+ 4 - 0
src/check_expr.cpp

@@ -9131,6 +9131,10 @@ gb_internal ExprKind check_or_branch_expr(CheckerContext *c, Operand *o, Ast *no
 	}
 	}
 
 
 	if (label != nullptr) {
 	if (label != nullptr) {
+		if (c->in_defer) {
+			error(label, "A labelled '%.*s' cannot be used within a 'defer'", LIT(name));
+			return Expr_Expr;
+		}
 		if (label->kind != Ast_Ident) {
 		if (label->kind != Ast_Ident) {
 			error(label, "A branch statement's label name must be an identifier");
 			error(label, "A branch statement's label name must be an identifier");
 			return Expr_Expr;
 			return Expr_Expr;