aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-07-13 15:59:46 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-07-13 16:10:41 -0700
commitfad95741db7529bbad873fb330c25d64ac765340 (patch)
tree22ca663d66d22bccc6ffe9ac0d2c676ed8bb0636 /src
parent1fee9eac8bb5d2e3e78c098b9cebe2cda332e7cf (diff)
downloadzig-fad95741db7529bbad873fb330c25d64ac765340.tar.gz
zig-fad95741db7529bbad873fb330c25d64ac765340.zip
AstGen: fix loop control flow applying to wrong loop
In the case of 'continue' or 'break' inside the 'else' block of a 'while' or 'for' loop. Closes #12109
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 7220fe758d..252610aeeb 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -5795,6 +5795,10 @@ fn whileExpr(
break :s &else_scope.base;
}
};
+ // Remove the continue block and break block so that `continue` and `break`
+ // control flow apply to outer loops; not this one.
+ loop_scope.continue_block = 0;
+ loop_scope.break_block = 0;
const e = try expr(&else_scope, sub_scope, loop_scope.break_result_loc, else_node);
if (!else_scope.endsWithNoReturn()) {
loop_scope.break_count += 1;
@@ -5994,6 +5998,10 @@ fn forExpr(
result: Zir.Inst.Ref,
} = if (else_node != 0) blk: {
const sub_scope = &else_scope.base;
+ // Remove the continue block and break block so that `continue` and `break`
+ // control flow apply to outer loops; not this one.
+ loop_scope.continue_block = 0;
+ loop_scope.break_block = 0;
const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_loc, else_node);
if (!else_scope.endsWithNoReturn()) {
loop_scope.break_count += 1;