From 0a0c11685fd8faf73392d88dbdee7c744cc83386 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 27 Jun 2019 17:22:35 -0400 Subject: [PATCH] fix for with null and T peer types and inferred result location type See #2762 --- src/ir.cpp | 6 +++--- test/stage1/behavior/for.zig | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 74f6d0485d..abae52fcb5 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6521,7 +6521,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo loop_scope->is_comptime = is_comptime; loop_scope->incoming_blocks = &incoming_blocks; loop_scope->incoming_values = &incoming_values; - loop_scope->lval = lval; + loop_scope->lval = LValNone; loop_scope->peer_parent = peer_parent; // Note the body block of the loop is not the place that lval and result_loc are used - @@ -6548,7 +6548,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo } ResultLocPeer *peer_result = create_peer_result(peer_parent); peer_parent->peers.append(peer_result); - else_result = ir_gen_node_extra(irb, else_node, parent_scope, lval, &peer_result->base); + else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base); if (else_result == irb->codegen->invalid_instruction) return else_result; if (!instr_is_unreachable(else_result)) @@ -6570,7 +6570,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items, peer_parent); - return ir_expr_wrap(irb, parent_scope, phi, result_loc); + return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); } static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) { diff --git a/test/stage1/behavior/for.zig b/test/stage1/behavior/for.zig index 63205b9e7d..cfa68bd216 100644 --- a/test/stage1/behavior/for.zig +++ b/test/stage1/behavior/for.zig @@ -126,3 +126,19 @@ test "2 break statements and an else" { S.entry(true, false); comptime S.entry(true, false); } + +test "for with null and T peer types and inferred result location type" { + const S = struct { + fn doTheTest(slice: []const u8) void { + if (for (slice) |item| { + if (item == 10) { + break item; + } + } else null) |v| { + @panic("fail"); + } + } + }; + S.doTheTest([_]u8{ 1, 2 }); + comptime S.doTheTest([_]u8{ 1, 2 }); +}