| author | |
| committer | |
| log | f99b8b006fe458ee717acc6c8de6170fc453acb7 |
| tree | 672b663987df03e6b70e384b39b565272c9efbf1 |
| parent | 6940212ecbef349e449441e1fd813116865d3a5f |
4 files changed, 49 insertions(+), 22 deletions(-)
src/ir.cpp+19-1| ... | ... | @@ -9361,6 +9361,24 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 9361 | 9361 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 9362 | 9362 | return ira->codegen->builtin_types.entry_invalid; |
| 9363 | 9363 | } |
| 9364 | // exception if one of the operators has the type of the empty error set, we allow the comparison | |
| 9365 | // (and make it comptime known) | |
| 9366 | // this is a function which is evaluated at comptime and returns an inferred error set will have an empty | |
| 9367 | // error set. | |
| 9368 | if (op1->value.type->data.error_set.err_count == 0 || op2->value.type->data.error_set.err_count == 0) { | |
| 9369 | bool are_equal = false; | |
| 9370 | bool answer; | |
| 9371 | if (op_id == IrBinOpCmpEq) { | |
| 9372 | answer = are_equal; | |
| 9373 | } else if (op_id == IrBinOpCmpNotEq) { | |
| 9374 | answer = !are_equal; | |
| 9375 | } else { | |
| 9376 | zig_unreachable(); | |
| 9377 | } | |
| 9378 | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); | |
| 9379 | out_val->data.x_bool = answer; | |
| 9380 | return ira->codegen->builtin_types.entry_bool; | |
| 9381 | } | |
| 9364 | 9382 | TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); |
| 9365 | 9383 | if (type_is_invalid(intersect_type)) { |
| 9366 | 9384 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15352,7 +15370,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 15352 | 15370 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 15353 | 15371 | if (err != nullptr) { |
| 15354 | 15372 | ir_add_error(ira, &instruction->base, |
| 15355 | buf_sprintf("unable to unwrap error '%s'", buf_ptr(&err->name))); | |
| 15373 | buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name))); | |
| 15356 | 15374 | return ira->codegen->builtin_types.entry_invalid; |
| 15357 | 15375 | } |
| 15358 | 15376 |
std/fmt/index.zig+4-4| ... | ... | @@ -439,9 +439,9 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { |
| 439 | 439 | test "fmt.parseInt" { |
| 440 | 440 | assert((parseInt(i32, "-10", 10) catch unreachable) == -10); |
| 441 | 441 | assert((parseInt(i32, "+10", 10) catch unreachable) == 10); |
| 442 | assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidChar); | |
| 443 | assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidChar); | |
| 444 | assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidChar); | |
| 442 | assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 443 | assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 444 | assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 445 | 445 | assert((parseInt(u8, "255", 10) catch unreachable) == 255); |
| 446 | 446 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); |
| 447 | 447 | } |
| ... | ... | @@ -538,7 +538,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u |
| 538 | 538 | |
| 539 | 539 | test "parse u64 digit too big" { |
| 540 | 540 | _ = parseUnsigned(u64, "123a", 10) catch |err| { |
| 541 | if (err == error.InvalidChar) return; | |
| 541 | if (err == error.InvalidCharacter) return; | |
| 542 | 542 | unreachable; |
| 543 | 543 | }; |
| 544 | 544 | unreachable; |
std/io.zig+24-15| ... | ... | @@ -550,21 +550,24 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len |
| 550 | 550 | return buf; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | pub const BufferedInStream = BufferedInStreamCustom(os.page_size); | |
| 553 | pub fn BufferedInStream(comptime Error: type) type { | |
| 554 | return BufferedInStreamCustom(os.page_size, Error); | |
| 555 | } | |
| 554 | 556 | |
| 555 | pub fn BufferedInStreamCustom(comptime buffer_size: usize) type { | |
| 557 | pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type { | |
| 556 | 558 | return struct { |
| 557 | 559 | const Self = this; |
| 560 | const Stream = InStream(Error); | |
| 558 | 561 | |
| 559 | pub stream: InStream, | |
| 562 | pub stream: Stream, | |
| 560 | 563 | |
| 561 | unbuffered_in_stream: &InStream, | |
| 564 | unbuffered_in_stream: &Stream, | |
| 562 | 565 | |
| 563 | 566 | buffer: [buffer_size]u8, |
| 564 | 567 | start_index: usize, |
| 565 | 568 | end_index: usize, |
| 566 | 569 | |
| 567 | pub fn init(unbuffered_in_stream: &InStream) Self { | |
| 570 | pub fn init(unbuffered_in_stream: &Stream) Self { | |
| 568 | 571 | return Self { |
| 569 | 572 | .unbuffered_in_stream = unbuffered_in_stream, |
| 570 | 573 | .buffer = undefined, |
| ... | ... | @@ -576,13 +579,13 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) type { |
| 576 | 579 | .start_index = buffer_size, |
| 577 | 580 | .end_index = buffer_size, |
| 578 | 581 | |
| 579 | .stream = InStream { | |
| 582 | .stream = Stream { | |
| 580 | 583 | .readFn = readFn, |
| 581 | 584 | }, |
| 582 | 585 | }; |
| 583 | 586 | } |
| 584 | 587 | |
| 585 | fn readFn(in_stream: &InStream, dest: []u8) !usize { | |
| 588 | fn readFn(in_stream: &Stream, dest: []u8) !usize { | |
| 586 | 589 | const self = @fieldParentPtr(Self, "stream", in_stream); |
| 587 | 590 | |
| 588 | 591 | var dest_index: usize = 0; |
| ... | ... | @@ -621,25 +624,28 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) type { |
| 621 | 624 | }; |
| 622 | 625 | } |
| 623 | 626 | |
| 624 | pub const BufferedOutStream = BufferedOutStreamCustom(os.page_size); | |
| 627 | pub fn BufferedOutStream(comptime Error: type) type { | |
| 628 | return BufferedOutStreamCustom(os.page_size, Error); | |
| 629 | } | |
| 625 | 630 | |
| 626 | pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type { | |
| 631 | pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime Error: type) type { | |
| 627 | 632 | return struct { |
| 628 | 633 | const Self = this; |
| 634 | const Stream = OutStream(Error); | |
| 629 | 635 | |
| 630 | pub stream: OutStream, | |
| 636 | pub stream: Stream, | |
| 631 | 637 | |
| 632 | unbuffered_out_stream: &OutStream, | |
| 638 | unbuffered_out_stream: &Stream, | |
| 633 | 639 | |
| 634 | 640 | buffer: [buffer_size]u8, |
| 635 | 641 | index: usize, |
| 636 | 642 | |
| 637 | pub fn init(unbuffered_out_stream: &OutStream) Self { | |
| 643 | pub fn init(unbuffered_out_stream: &Stream) Self { | |
| 638 | 644 | return Self { |
| 639 | 645 | .unbuffered_out_stream = unbuffered_out_stream, |
| 640 | 646 | .buffer = undefined, |
| 641 | 647 | .index = 0, |
| 642 | .stream = OutStream { | |
| 648 | .stream = Stream { | |
| 643 | 649 | .writeFn = writeFn, |
| 644 | 650 | }, |
| 645 | 651 | }; |
| ... | ... | @@ -653,7 +659,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type { |
| 653 | 659 | self.index = 0; |
| 654 | 660 | } |
| 655 | 661 | |
| 656 | fn writeFn(out_stream: &OutStream, bytes: []const u8) !void { | |
| 662 | fn writeFn(out_stream: &Stream, bytes: []const u8) !void { | |
| 657 | 663 | const self = @fieldParentPtr(Self, "stream", out_stream); |
| 658 | 664 | |
| 659 | 665 | if (bytes.len >= self.buffer.len) { |
| ... | ... | @@ -680,7 +686,10 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type { |
| 680 | 686 | /// Implementation of OutStream trait for Buffer |
| 681 | 687 | pub const BufferOutStream = struct { |
| 682 | 688 | buffer: &Buffer, |
| 683 | stream: OutStream, | |
| 689 | stream: Stream, | |
| 690 | ||
| 691 | pub const Error = error{OutOfMemory}; | |
| 692 | pub const Stream = OutStream(Error); | |
| 684 | 693 | |
| 685 | 694 | pub fn init(buffer: &Buffer) BufferOutStream { |
| 686 | 695 | return BufferOutStream { |
std/io_test.zig+2-2| ... | ... | @@ -17,7 +17,7 @@ test "write a file, read it, then delete it" { |
| 17 | 17 | defer file.close(); |
| 18 | 18 | |
| 19 | 19 | var file_out_stream = io.FileOutStream.init(&file); |
| 20 | var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream); | |
| 20 | var buf_stream = io.BufferedOutStream(io.FileOutStream.Error).init(&file_out_stream.stream); | |
| 21 | 21 | const st = &buf_stream.stream; |
| 22 | 22 | try st.print("begin"); |
| 23 | 23 | try st.write(data[0..]); |
| ... | ... | @@ -33,7 +33,7 @@ test "write a file, read it, then delete it" { |
| 33 | 33 | assert(file_size == expected_file_size); |
| 34 | 34 | |
| 35 | 35 | var file_in_stream = io.FileInStream.init(&file); |
| 36 | var buf_stream = io.BufferedInStream.init(&file_in_stream.stream); | |
| 36 | var buf_stream = io.BufferedInStream(io.FileInStream.Error).init(&file_in_stream.stream); | |
| 37 | 37 | const st = &buf_stream.stream; |
| 38 | 38 | const contents = try st.readAllAlloc(allocator, 2 * 1024); |
| 39 | 39 | defer allocator.free(contents); |