| ... | @@ -4263,6 +4263,7 @@ fn forExpr( | ... | @@ -4263,6 +4263,7 @@ fn forExpr( |
| 4263 | }; | 4263 | }; |
| 4264 | defer then_scope.instructions.deinit(astgen.gpa); | 4264 | defer then_scope.instructions.deinit(astgen.gpa); |
| 4265 | | 4265 | |
| | 4266 | var payload_val_scope: Scope.LocalVal = undefined; |
| 4266 | var index_scope: Scope.LocalPtr = undefined; | 4267 | var index_scope: Scope.LocalPtr = undefined; |
| 4267 | const then_sub_scope = blk: { | 4268 | const then_sub_scope = blk: { |
| 4268 | const payload_token = for_full.payload_token.?; | 4269 | const payload_token = for_full.payload_token.?; |
| ... | @@ -4272,22 +4273,34 @@ fn forExpr( | ... | @@ -4272,22 +4273,34 @@ fn forExpr( |
| 4272 | payload_token; | 4273 | payload_token; |
| 4273 | const is_ptr = ident != payload_token; | 4274 | const is_ptr = ident != payload_token; |
| 4274 | const value_name = tree.tokenSlice(ident); | 4275 | const value_name = tree.tokenSlice(ident); |
| | 4276 | var payload_sub_scope: *Scope = undefined; |
| 4275 | if (!mem.eql(u8, value_name, "_")) { | 4277 | if (!mem.eql(u8, value_name, "_")) { |
| 4276 | return astgen.failTok(ident, "TODO implement for loop value payload", .{}); | 4278 | const tag: Zir.Inst.Tag = if (is_ptr) .elem_ptr else .elem_val; |
| | 4279 | const payload_inst = try then_scope.addBin(tag, array_ptr, index); |
| | 4280 | payload_val_scope = .{ |
| | 4281 | .parent = &then_scope.base, |
| | 4282 | .gen_zir = &then_scope, |
| | 4283 | .name = value_name, |
| | 4284 | .inst = payload_inst, |
| | 4285 | .token_src = ident, |
| | 4286 | }; |
| | 4287 | payload_sub_scope = &payload_val_scope.base; |
| 4277 | } else if (is_ptr) { | 4288 | } else if (is_ptr) { |
| 4278 | return astgen.failTok(payload_token, "pointer modifier invalid on discard", .{}); | 4289 | return astgen.failTok(payload_token, "pointer modifier invalid on discard", .{}); |
| | 4290 | } else { |
| | 4291 | payload_sub_scope = &then_scope.base; |
| 4279 | } | 4292 | } |
| 4280 | | 4293 | |
| 4281 | const index_token = if (token_tags[ident + 1] == .comma) | 4294 | const index_token = if (token_tags[ident + 1] == .comma) |
| 4282 | ident + 2 | 4295 | ident + 2 |
| 4283 | else | 4296 | else |
| 4284 | break :blk &then_scope.base; | 4297 | break :blk payload_sub_scope; |
| 4285 | if (mem.eql(u8, tree.tokenSlice(index_token), "_")) { | 4298 | if (mem.eql(u8, tree.tokenSlice(index_token), "_")) { |
| 4286 | return astgen.failTok(index_token, "discard of index capture; omit it instead", .{}); | 4299 | return astgen.failTok(index_token, "discard of index capture; omit it instead", .{}); |
| 4287 | } | 4300 | } |
| 4288 | const index_name = try astgen.identifierTokenString(index_token); | 4301 | const index_name = try astgen.identifierTokenString(index_token); |
| 4289 | index_scope = .{ | 4302 | index_scope = .{ |
| 4290 | .parent = &then_scope.base, | 4303 | .parent = payload_sub_scope, |
| 4291 | .gen_zir = &then_scope, | 4304 | .gen_zir = &then_scope, |
| 4292 | .name = index_name, | 4305 | .name = index_name, |
| 4293 | .ptr = index_ptr, | 4306 | .ptr = index_ptr, |