| author | |
| committer | |
| log | 66e5e92a3e958c8097a2366ff74f34ebdad40154 |
| tree | 5b65b2b979dbdf72bf24103428ac1f3d902059ed |
| parent | d95724454c84b22e9030aec69b88d1fa9fd5175b |
| parent | 2561168adbe642287c1eccd73fc29576ff0216f3 |
| signature |
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,10 +413,7 @@ pub const DwarfInfo = struct { |
| 413 | var this_unit_offset: u64 = 0; | 413 | var this_unit_offset: u64 = 0; |
| 414 | 414 | ||
| 415 | while (this_unit_offset < try seekable.getEndPos()) { | 415 | while (this_unit_offset < try seekable.getEndPos()) { |
| 416 | seekable.seekTo(this_unit_offset) catch |err| switch (err) { | 416 | try seekable.seekTo(this_unit_offset); |
| 417 | error.EndOfStream => unreachable, | ||
| 418 | else => return err, | ||
| 419 | }; | ||
| 420 | 417 | ||
| 421 | var is_64: bool = undefined; | 418 | var is_64: bool = undefined; |
| 422 | const unit_length = try readUnitLength(in, di.endian, &is_64); | 419 | const unit_length = try readUnitLength(in, di.endian, &is_64); |
| ... | @@ -520,10 +517,7 @@ pub const DwarfInfo = struct { | ... | @@ -520,10 +517,7 @@ pub const DwarfInfo = struct { |
| 520 | var this_unit_offset: u64 = 0; | 517 | var this_unit_offset: u64 = 0; |
| 521 | 518 | ||
| 522 | while (this_unit_offset < try seekable.getEndPos()) { | 519 | while (this_unit_offset < try seekable.getEndPos()) { |
| 523 | seekable.seekTo(this_unit_offset) catch |err| switch (err) { | 520 | try seekable.seekTo(this_unit_offset); |
| 524 | error.EndOfStream => unreachable, | ||
| 525 | else => return err, | ||
| 526 | }; | ||
| 527 | 521 | ||
| 528 | var is_64: bool = undefined; | 522 | var is_64: bool = undefined; |
| 529 | const unit_length = try readUnitLength(in, di.endian, &is_64); | 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,6 +24207,8 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 24207 | ref_type->data.pointer.allow_zero); | 24207 | ref_type->data.pointer.allow_zero); |
| 24208 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, | 24208 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 24209 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false); | 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 | } else { | 24212 | } else { |
| 24211 | ir_add_error(ira, &instruction->base.base, | 24213 | ir_add_error(ira, &instruction->base.base, |
| 24212 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); | 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,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 | var state: u32 = 0; | 459 | var state: u32 = 0; |
| 440 | fn poll() void { | 460 | fn poll() void { |
| 441 | switch (state) { | 461 | switch (state) { |
test/stage1/behavior/union.zig+2-2| ... | @@ -742,7 +742,7 @@ test "@unionInit on union w/ tag but no fields" { | ... | @@ -742,7 +742,7 @@ test "@unionInit on union w/ tag but no fields" { |
| 742 | const Data = union(Type) { | 742 | const Data = union(Type) { |
| 743 | no_op: void, | 743 | no_op: void, |
| 744 | 744 | ||
| 745 | pub fn decode(buf: []const u8) !Data { | 745 | pub fn decode(buf: []const u8) Data { |
| 746 | return @unionInit(Data, "no_op", {}); | 746 | return @unionInit(Data, "no_op", {}); |
| 747 | } | 747 | } |
| 748 | }; | 748 | }; |
| ... | @@ -753,7 +753,7 @@ test "@unionInit on union w/ tag but no fields" { | ... | @@ -753,7 +753,7 @@ test "@unionInit on union w/ tag but no fields" { |
| 753 | 753 | ||
| 754 | fn doTheTest() void { | 754 | fn doTheTest() void { |
| 755 | var data: Data = .{ .no_op = .{} }; | 755 | var data: Data = .{ .no_op = .{} }; |
| 756 | var o = try Data.decode(&[_]u8{}); | 756 | var o = Data.decode(&[_]u8{}); |
| 757 | expectEqual(Type.no_op, o); | 757 | expectEqual(Type.no_op, o); |
| 758 | } | 758 | } |
| 759 | }; | 759 | }; |