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 *...@@ -7156,7 +7156,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
7156 ir_set_cursor_at_end_and_append_block(irb, else_block);7156 ir_set_cursor_at_end_and_append_block(irb, else_block);
7157 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,7157 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
7158 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,7158 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))
7160 {7160 {
7161 return irb->codegen->invalid_instruction;7161 return irb->codegen->invalid_instruction;
7162 }7162 }
...@@ -7233,7 +7233,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7233,7 +7233,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
7233 ir_set_cursor_at_end_and_append_block(irb, range_block_yes);7233 ir_set_cursor_at_end_and_append_block(irb, range_block_yes);
7234 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,7234 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
7235 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,7235 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))
7237 {7237 {
7238 return irb->codegen->invalid_instruction;7238 return irb->codegen->invalid_instruction;
7239 }7239 }
...@@ -7283,7 +7283,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7283,7 +7283,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
7283 ir_set_cursor_at_end_and_append_block(irb, prong_block);7283 ir_set_cursor_at_end_and_append_block(irb, prong_block);
7284 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,7284 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
7285 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,7285 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))
7287 {7287 {
7288 return irb->codegen->invalid_instruction;7288 return irb->codegen->invalid_instruction;
7289 }7289 }
...@@ -7334,7 +7334,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7334,7 +7334,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
7334 result_instruction = ir_build_phi(irb, scope, node, incoming_blocks.length,7334 result_instruction = ir_build_phi(irb, scope, node, incoming_blocks.length,
7335 incoming_blocks.items, incoming_values.items, peer_parent);7335 incoming_blocks.items, incoming_values.items, peer_parent);
7336 }7336 }
7337 return ir_expr_wrap(irb, scope, result_instruction, result_loc);7337 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);
7338}7338}
73397339
7340static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) {7340static 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...@@ -376,3 +376,18 @@ test "return result loc and then switch with range implicit casted to error unio
376 S.doTheTest();376 S.doTheTest();
377 comptime S.doTheTest();377 comptime S.doTheTest();
378}378}
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}