| author | |
| committer | |
| log | 66e5e92a3e958c8097a2366ff74f34ebdad40154 |
| tree | 5b65b2b979dbdf72bf24103428ac1f3d902059ed |
| parent | d95724454c84b22e9030aec69b88d1fa9fd5175b |
| parent | 2561168adbe642287c1eccd73fc29576ff0216f3 |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
Allow variable captures on multi-prong switch arms4 files changed, 26 insertions(+), 10 deletions(-)
lib/std/dwarf.zig+2-8| ... | ... | @@ -413,10 +413,7 @@ pub const DwarfInfo = struct { |
| 413 | 413 | var this_unit_offset: u64 = 0; |
| 414 | 414 | |
| 415 | 415 | while (this_unit_offset < try seekable.getEndPos()) { |
| 416 | seekable.seekTo(this_unit_offset) catch |err| switch (err) { | |
| 417 | error.EndOfStream => unreachable, | |
| 418 | else => return err, | |
| 419 | }; | |
| 416 | try seekable.seekTo(this_unit_offset); | |
| 420 | 417 | |
| 421 | 418 | var is_64: bool = undefined; |
| 422 | 419 | const unit_length = try readUnitLength(in, di.endian, &is_64); |
| ... | ... | @@ -520,10 +517,7 @@ pub const DwarfInfo = struct { |
| 520 | 517 | var this_unit_offset: u64 = 0; |
| 521 | 518 | |
| 522 | 519 | while (this_unit_offset < try seekable.getEndPos()) { |
| 523 | seekable.seekTo(this_unit_offset) catch |err| switch (err) { | |
| 524 | error.EndOfStream => unreachable, | |
| 525 | else => return err, | |
| 526 | }; | |
| 520 | try seekable.seekTo(this_unit_offset); | |
| 527 | 521 | |
| 528 | 522 | var is_64: bool = undefined; |
| 529 | 523 | const unit_length = try readUnitLength(in, di.endian, &is_64); |
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) { |
test/stage1/behavior/union.zig+2-2| ... | ... | @@ -742,7 +742,7 @@ test "@unionInit on union w/ tag but no fields" { |
| 742 | 742 | const Data = union(Type) { |
| 743 | 743 | no_op: void, |
| 744 | 744 | |
| 745 | pub fn decode(buf: []const u8) !Data { | |
| 745 | pub fn decode(buf: []const u8) Data { | |
| 746 | 746 | return @unionInit(Data, "no_op", {}); |
| 747 | 747 | } |
| 748 | 748 | }; |
| ... | ... | @@ -753,7 +753,7 @@ test "@unionInit on union w/ tag but no fields" { |
| 753 | 753 | |
| 754 | 754 | fn doTheTest() void { |
| 755 | 755 | var data: Data = .{ .no_op = .{} }; |
| 756 | var o = try Data.decode(&[_]u8{}); | |
| 756 | var o = Data.decode(&[_]u8{}); | |
| 757 | 757 | expectEqual(Type.no_op, o); |
| 758 | 758 | } |
| 759 | 759 | }; |