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
This commit is contained in:
@@ -210,3 +210,17 @@ test "for on slice with allowzero ptr" {
|
||||
try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
|
||||
comptime try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
|
||||
}
|
||||
|
||||
test "else continue outer for" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
var i: usize = 6;
|
||||
var buf: [5]u8 = undefined;
|
||||
while (true) {
|
||||
i -= 1;
|
||||
for (buf[i..5]) |_| {
|
||||
return;
|
||||
} else continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,3 +334,13 @@ test "continue inline while loop" {
|
||||
}
|
||||
comptime assert(i == 5);
|
||||
}
|
||||
|
||||
test "else continue outer while" {
|
||||
var i: usize = 0;
|
||||
while (true) {
|
||||
i += 1;
|
||||
while (i > 5) {
|
||||
return;
|
||||
} else continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user