authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-21 11:12:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-21 17:03:03-07:00
loga04a98ff3e800136f624d97e315304f515376035
treefb678f7faf662f02c5d6272706837f44b74833ba
parent4f900e68d32be271f08e8b8844c725e0a595c467

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.

1 files changed, 20 insertions(+), 20 deletions(-)

src/AstGen.zig+20-20
......@@ -5192,26 +5192,6 @@ fn whileExpr(
51925192 try loop_scope.instructions.append(astgen.gpa, cond_block);
51935193 try continue_scope.setBlockBody(cond_block);
51945194
5195 // This code could be improved to avoid emitting the continue expr when there
5196 // are no jumps to it. This happens when the last statement of a while body is noreturn
5197 // and there are no `continue` statements.
5198 // Tracking issue: https://github.com/ziglang/zig/issues/9185
5199 if (while_full.ast.cont_expr != 0) {
5200 _ = try expr(&loop_scope, &loop_scope.base, .{ .ty = .void_type }, while_full.ast.cont_expr);
5201 }
5202 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
5203 _ = try loop_scope.addNode(repeat_tag, node);
5204
5205 try loop_scope.setBlockBody(loop_block);
5206 loop_scope.break_block = loop_block;
5207 loop_scope.continue_block = cond_block;
5208 if (while_full.label_token) |label_token| {
5209 loop_scope.label = @as(?GenZir.Label, GenZir.Label{
5210 .token = label_token,
5211 .block_inst = loop_block,
5212 });
5213 }
5214
52155195 var then_scope = parent_gz.makeSubBlock(&continue_scope.base);
52165196 defer then_scope.instructions.deinit(astgen.gpa);
52175197
......@@ -5265,6 +5245,26 @@ fn whileExpr(
52655245 }
52665246 };
52675247
5248 // This code could be improved to avoid emitting the continue expr when there
5249 // are no jumps to it. This happens when the last statement of a while body is noreturn
5250 // and there are no `continue` statements.
5251 // Tracking issue: https://github.com/ziglang/zig/issues/9185
5252 if (while_full.ast.cont_expr != 0) {
5253 _ = try expr(&loop_scope, then_sub_scope, .{ .ty = .void_type }, while_full.ast.cont_expr);
5254 }
5255 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
5256 _ = try loop_scope.addNode(repeat_tag, node);
5257
5258 try loop_scope.setBlockBody(loop_block);
5259 loop_scope.break_block = loop_block;
5260 loop_scope.continue_block = cond_block;
5261 if (while_full.label_token) |label_token| {
5262 loop_scope.label = @as(?GenZir.Label, GenZir.Label{
5263 .token = label_token,
5264 .block_inst = loop_block,
5265 });
5266 }
5267
52685268 loop_scope.break_count += 1;
52695269 const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, while_full.ast.then_expr);
52705270 try checkUsed(parent_gz, &then_scope.base, then_sub_scope);