| author | |
| committer | |
| log | 88634f0481fb1bd78f8d018b76cab6590691c8a9 |
| tree | 68f4e1cc2f26f176de68c880e83b8f2484165928 |
| parent | 3634d44d08c73326c7783cf2a3095acb50eb2e1c |
Handle the multi-prong case as we do with range cases.
Closes #71882 files changed, 22 insertions(+), 0 deletions(-)
src/stage1/ir.cpp+2| ... | ... | @@ -24207,6 +24207,8 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 24207 | 24207 | ref_type->data.pointer.allow_zero); |
| 24208 | 24208 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 24209 | 24209 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false); |
| 24210 | } else if (instruction->prongs_len > 1) { | |
| 24211 | return target_value_ptr; | |
| 24210 | 24212 | } else { |
| 24211 | 24213 | ir_add_error(ira, &instruction->base.base, |
| 24212 | 24214 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
test/stage1/behavior/switch.zig+20| ... | ... | @@ -436,6 +436,26 @@ test "switch with disjoint range" { |
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | test "switch variable for range and multiple prongs" { | |
| 440 | const S = struct { | |
| 441 | fn doTheTest() void { | |
| 442 | var u: u8 = 16; | |
| 443 | doTheSwitch(u); | |
| 444 | comptime doTheSwitch(u); | |
| 445 | var v: u8 = 42; | |
| 446 | doTheSwitch(v); | |
| 447 | comptime doTheSwitch(v); | |
| 448 | } | |
| 449 | fn doTheSwitch(q: u8) void { | |
| 450 | switch (q) { | |
| 451 | 0...40 => |x| expect(x == 16), | |
| 452 | 41, 42, 43 => |x| expect(x == 42), | |
| 453 | else => expect(false), | |
| 454 | } | |
| 455 | } | |
| 456 | }; | |
| 457 | } | |
| 458 | ||
| 439 | 459 | var state: u32 = 0; |
| 440 | 460 | fn poll() void { |
| 441 | 461 | switch (state) { |