fix capturing value of switch with all unreachable prongs

closes #635
This commit is contained in:
Andrew Kelley 2017-11-29 21:33:58 -05:00
parent ccea8dcbf6
commit 716b0b8655
3 changed files with 14 additions and 3 deletions

View File

@ -4664,7 +4664,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name));
return;
case TypeTableEntryIdUnreachable:
buf_appendf(buf, "@unreachable()");
buf_appendf(buf, "unreachable");
return;
case TypeTableEntryIdBool:
{

View File

@ -11154,8 +11154,8 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
}
if (new_incoming_blocks.length == 0) {
ir_build_const_from(ira, &phi_instruction->base);
return ira->codegen->builtin_types.entry_void;
ir_build_unreachable_from(&ira->new_irb, &phi_instruction->base);
return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
}
if (new_incoming_blocks.length == 1) {

View File

@ -224,3 +224,14 @@ fn switchWithUnreachable(x: i32) -> i32 {
}
return 10;
}
fn return_a_number() -> %i32 {
return 1;
}
test "capture value of switch with all unreachable prongs" {
const x = return_a_number() %% |err| switch (err) {
else => unreachable,
};
assert(x == 1);
}