diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-06-21 11:12:45 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-06-21 17:03:03 -0700 |
| commit | a04a98ff3e800136f624d97e315304f515376035 (patch) | |
| tree | fb678f7faf662f02c5d6272706837f44b74833ba /src/AstGen.zig | |
| parent | 4f900e68d32be271f08e8b8844c725e0a595c467 (diff) | |
| download | zig-a04a98ff3e800136f624d97e315304f515376035.tar.gz zig-a04a98ff3e800136f624d97e315304f515376035.zip | |
AstGen: while loop continue expr captures in scope
Before this, the continue expression of a while loop did not have the
capture variable in it, making it incorrectly emit a compile error for
not using the capture, even if it was referenced.
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index e08d650936..7180f0973b 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -5192,26 +5192,6 @@ fn whileExpr( try loop_scope.instructions.append(astgen.gpa, cond_block); try continue_scope.setBlockBody(cond_block); - // This code could be improved to avoid emitting the continue expr when there - // are no jumps to it. This happens when the last statement of a while body is noreturn - // and there are no `continue` statements. - // Tracking issue: https://github.com/ziglang/zig/issues/9185 - if (while_full.ast.cont_expr != 0) { - _ = try expr(&loop_scope, &loop_scope.base, .{ .ty = .void_type }, while_full.ast.cont_expr); - } - const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat; - _ = try loop_scope.addNode(repeat_tag, node); - - try loop_scope.setBlockBody(loop_block); - loop_scope.break_block = loop_block; - loop_scope.continue_block = cond_block; - if (while_full.label_token) |label_token| { - loop_scope.label = @as(?GenZir.Label, GenZir.Label{ - .token = label_token, - .block_inst = loop_block, - }); - } - var then_scope = parent_gz.makeSubBlock(&continue_scope.base); defer then_scope.instructions.deinit(astgen.gpa); @@ -5265,6 +5245,26 @@ fn whileExpr( } }; + // This code could be improved to avoid emitting the continue expr when there + // are no jumps to it. This happens when the last statement of a while body is noreturn + // and there are no `continue` statements. + // Tracking issue: https://github.com/ziglang/zig/issues/9185 + if (while_full.ast.cont_expr != 0) { + _ = try expr(&loop_scope, then_sub_scope, .{ .ty = .void_type }, while_full.ast.cont_expr); + } + const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat; + _ = try loop_scope.addNode(repeat_tag, node); + + try loop_scope.setBlockBody(loop_block); + loop_scope.break_block = loop_block; + loop_scope.continue_block = cond_block; + if (while_full.label_token) |label_token| { + loop_scope.label = @as(?GenZir.Label, GenZir.Label{ + .token = label_token, + .block_inst = loop_block, + }); + } + loop_scope.break_count += 1; const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, while_full.ast.then_expr); try checkUsed(parent_gz, &then_scope.base, then_sub_scope); |
