diff --git a/src/analyze.cpp b/src/analyze.cpp index 1c223c63f7..a12934f2b2 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -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: { diff --git a/src/ir.cpp b/src/ir.cpp index 7c15b48bee..f1dc1e1b4d 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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) { diff --git a/test/cases/switch.zig b/test/cases/switch.zig index 154e251a04..9ec50c7e25 100644 --- a/test/cases/switch.zig +++ b/test/cases/switch.zig @@ -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); +}