authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 16:54:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 16:54:19-04:00
log1b23c461380dea2a2b04eb234652a705f01f05a7
tree91bedf1ec4f587d27842b2ba4ab3ebf6550710ae
parentd422d5753b64b57b8559ceee45081f4e1e355e54
signature Commit is signed but in an unrecognized format.

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

closes #2762

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

src/ir.cpp+4-4
......@@ -7156,7 +7156,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
71567156 ir_set_cursor_at_end_and_append_block(irb, else_block);
71577157 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
71587158 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,
7159 &switch_else_var, lval, &this_peer_result_loc->base))
7159 &switch_else_var, LValNone, &this_peer_result_loc->base))
71607160 {
71617161 return irb->codegen->invalid_instruction;
71627162 }
......@@ -7233,7 +7233,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
72337233 ir_set_cursor_at_end_and_append_block(irb, range_block_yes);
72347234 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
72357235 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,
7236 &incoming_blocks, &incoming_values, nullptr, lval, &this_peer_result_loc->base))
7236 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
72377237 {
72387238 return irb->codegen->invalid_instruction;
72397239 }
......@@ -7283,7 +7283,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
72837283 ir_set_cursor_at_end_and_append_block(irb, prong_block);
72847284 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
72857285 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,
7286 &incoming_blocks, &incoming_values, nullptr, lval, &this_peer_result_loc->base))
7286 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
72877287 {
72887288 return irb->codegen->invalid_instruction;
72897289 }
......@@ -7334,7 +7334,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
73347334 result_instruction = ir_build_phi(irb, scope, node, incoming_blocks.length,
73357335 incoming_blocks.items, incoming_values.items, peer_parent);
73367336 }
7337 return ir_expr_wrap(irb, scope, result_instruction, result_loc);
7337 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);
73387338}
73397339
73407340static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) {
test/stage1/behavior/switch.zig+15
......@@ -376,3 +376,18 @@ test "return result loc and then switch with range implicit casted to error unio
376376 S.doTheTest();
377377 comptime S.doTheTest();
378378}
379
380test "switch with null and T peer types and inferred result location type" {
381 const S = struct {
382 fn doTheTest(c: u8) void {
383 if (switch (c) {
384 0 => true,
385 else => null,
386 }) |v| {
387 @panic("fail");
388 }
389 }
390 };
391 S.doTheTest(1);
392 comptime S.doTheTest(1);
393}