| author | |
| committer | |
| log | 716b0b8655610a3a64818c51a91254c6e4715e49 |
| tree | 0933336a01ef47e578db46a90b7641c843a7c3ef |
| parent | ccea8dcbf61cc4483bc73ba45751e545a8f3541e |
closes #6353 files changed, 14 insertions(+), 3 deletions(-)
src/analyze.cpp+1-1| ... | @@ -4664,7 +4664,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { | ... | @@ -4664,7 +4664,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 4664 | buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name)); | 4664 | buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name)); |
| 4665 | return; | 4665 | return; |
| 4666 | case TypeTableEntryIdUnreachable: | 4666 | case TypeTableEntryIdUnreachable: |
| 4667 | buf_appendf(buf, "@unreachable()"); | 4667 | buf_appendf(buf, "unreachable"); |
| 4668 | return; | 4668 | return; |
| 4669 | case TypeTableEntryIdBool: | 4669 | case TypeTableEntryIdBool: |
| 4670 | { | 4670 | { |
src/ir.cpp+2-2| ... | @@ -11154,8 +11154,8 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP | ... | @@ -11154,8 +11154,8 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 11154 | } | 11154 | } |
| 11155 | 11155 | ||
| 11156 | if (new_incoming_blocks.length == 0) { | 11156 | if (new_incoming_blocks.length == 0) { |
| 11157 | ir_build_const_from(ira, &phi_instruction->base); | 11157 | ir_build_unreachable_from(&ira->new_irb, &phi_instruction->base); |
| 11158 | return ira->codegen->builtin_types.entry_void; | 11158 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 11159 | } | 11159 | } |
| 11160 | 11160 | ||
| 11161 | if (new_incoming_blocks.length == 1) { | 11161 | if (new_incoming_blocks.length == 1) { |
test/cases/switch.zig+11| ... | @@ -224,3 +224,14 @@ fn switchWithUnreachable(x: i32) -> i32 { | ... | @@ -224,3 +224,14 @@ fn switchWithUnreachable(x: i32) -> i32 { |
| 224 | } | 224 | } |
| 225 | return 10; | 225 | return 10; |
| 226 | } | 226 | } |
| 227 | |||
| 228 | fn return_a_number() -> %i32 { | ||
| 229 | return 1; | ||
| 230 | } | ||
| 231 | |||
| 232 | test "capture value of switch with all unreachable prongs" { | ||
| 233 | const x = return_a_number() %% |err| switch (err) { | ||
| 234 | else => unreachable, | ||
| 235 | }; | ||
| 236 | assert(x == 1); | ||
| 237 | } |