AstGen: fix ZIR for for loops accessing instruction out of block

This commit is contained in:
Andrew Kelley 2023-02-18 11:56:05 -07:00
parent 8c96d0dddd
commit 209e83f395

View File

@ -6413,6 +6413,8 @@ fn forExpr(
defer loop_scope.unstack();
defer loop_scope.labeled_breaks.deinit(gpa);
const index = try loop_scope.addUnNode(.load, index_ptr, node);
var cond_scope = parent_gz.makeSubBlock(&loop_scope.base);
defer cond_scope.unstack();
@ -6420,7 +6422,6 @@ fn forExpr(
if (!any_len_checks) {
return astgen.failNode(node, "TODO: handle infinite for loop", .{});
}
const index = try cond_scope.addUnNode(.load, index_ptr, node);
const cond = try cond_scope.addPlNode(.cmp_lt, node, Zir.Inst.Bin{
.lhs = index,
.rhs = len,
@ -10695,7 +10696,6 @@ const Scope = struct {
@"function parameter",
@"local constant",
@"local variable",
@"loop index capture",
@"switch tag capture",
capture,
};