authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 17:22:35-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 17:22:35-04:00
log0a0c11685fd8faf73392d88dbdee7c744cc83386
tree73ef6a0fc9f6d183f70bec3750182665e157a909
parent1b23c461380dea2a2b04eb234652a705f01f05a7
signaturelock-open Commit is signed but in an unrecognized format.

fix for with null and T peer types and inferred result location type

See #2762

2 files changed, 19 insertions(+), 3 deletions(-)

src/ir.cpp+3-3
......@@ -6521,7 +6521,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
65216521 loop_scope->is_comptime = is_comptime;
65226522 loop_scope->incoming_blocks = &incoming_blocks;
65236523 loop_scope->incoming_values = &incoming_values;
6524 loop_scope->lval = lval;
6524 loop_scope->lval = LValNone;
65256525 loop_scope->peer_parent = peer_parent;
65266526
65276527 // 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
65486548 }
65496549 ResultLocPeer *peer_result = create_peer_result(peer_parent);
65506550 peer_parent->peers.append(peer_result);
6551 else_result = ir_gen_node_extra(irb, else_node, parent_scope, lval, &peer_result->base);
6551 else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base);
65526552 if (else_result == irb->codegen->invalid_instruction)
65536553 return else_result;
65546554 if (!instr_is_unreachable(else_result))
......@@ -6570,7 +6570,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
65706570
65716571 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length,
65726572 incoming_blocks.items, incoming_values.items, peer_parent);
6573 return ir_expr_wrap(irb, parent_scope, phi, result_loc);
6573 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
65746574}
65756575
65766576static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
test/stage1/behavior/for.zig+16
......@@ -126,3 +126,19 @@ test "2 break statements and an else" {
126126 S.entry(true, false);
127127 comptime S.entry(true, false);
128128}
129
130test "for with null and T peer types and inferred result location type" {
131 const S = struct {
132 fn doTheTest(slice: []const u8) void {
133 if (for (slice) |item| {
134 if (item == 10) {
135 break item;
136 }
137 } else null) |v| {
138 @panic("fail");
139 }
140 }
141 };
142 S.doTheTest([_]u8{ 1, 2 });
143 comptime S.doTheTest([_]u8{ 1, 2 });
144}