| author | |
| committer | |
| log | 1d5f865cfafdaa96cac35ada9bb9e8b1a4e2bc36 |
| tree | 2715c03bfc0fff3e2a5845db86019912062d1dfa |
| parent | 046df9b7d001120a0142ea29c86cfb3b9ae4eadf |
in the presence of comptime control flow.
fixes #121712 files changed, 15 insertions(+), 0 deletions(-)
src/Sema.zig+4| ... | ... | @@ -4687,6 +4687,10 @@ fn resolveBlockBody( |
| 4687 | 4687 | return sema.analyzeBlockBody(parent_block, src, child_block, merges); |
| 4688 | 4688 | } else |err| switch (err) { |
| 4689 | 4689 | error.ComptimeBreak => { |
| 4690 | // Comptime control flow is happening, however child_block may still contain | |
| 4691 | // runtime instructions which need to be copied to the parent block. | |
| 4692 | try parent_block.instructions.appendSlice(sema.gpa, child_block.instructions.items); | |
| 4693 | ||
| 4690 | 4694 | const break_inst = sema.comptime_break_inst; |
| 4691 | 4695 | const break_data = sema.code.instructions.items(.data)[break_inst].@"break"; |
| 4692 | 4696 | if (break_data.block_inst == body_inst) { |
test/behavior/eval.zig+11| ... | ... | @@ -1261,3 +1261,14 @@ test "comptime write through extern struct reinterpreted as array" { |
| 1261 | 1261 | assert(s.c == 3); |
| 1262 | 1262 | } |
| 1263 | 1263 | } |
| 1264 | ||
| 1265 | test "continue nested in a conditional in an inline for" { | |
| 1266 | var x: u32 = 1; | |
| 1267 | inline for ([_]u8{ 1, 2, 3 }) |_| { | |
| 1268 | if (1 == 1) { | |
| 1269 | x = 0; | |
| 1270 | continue; | |
| 1271 | } | |
| 1272 | } | |
| 1273 | try expect(x == 0); | |
| 1274 | } |