zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 5936bdf8a4163d0c75444e5c8554316de63e3864 (tree)
parent b6489ff90afffcf0c69490efcb5941f3bb42fc3c
Author: tgschultz <tgschultz@gmail.com>
Date:   Fri, 30 Nov 2018 14:31:08 -0600

Fixed readBits to cast errors to the correct errorset. See #1810 for why this wasn't caught earlier.

Diffstat:
Mstd/io.zig | 4+++-
Mstd/io_test.zig | 8++++++++
2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/std/io.zig b/std/io.zig @@ -526,7 +526,9 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { if (err == error.EndOfStream) { return @intCast(U, out_buffer); } - return err; + //@BUG: See #1810. Not sure if the bug is that I have to do this for some + // streams, or that I don't for streams with emtpy errorsets. + return @errSetCast(Error, err); }; switch (endian) { diff --git a/std/io_test.zig b/std/io_test.zig @@ -169,6 +169,10 @@ test "BitInStream" { assert(out_bits == 16); _ = try bit_stream_be.readBits(u0, 0, &out_bits); + + assert(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); + assert(out_bits == 0); + assertError(bit_stream_be.readBitsNoEof(u1, 1), error.EndOfStream); var mem_in_le = io.SliceInStream.init(mem_le[0..]); var bit_stream_le = io.BitInStream(builtin.Endian.Little, InError).init(&mem_in_le.stream); @@ -197,6 +201,10 @@ test "BitInStream" { assert(out_bits == 16); _ = try bit_stream_le.readBits(u0, 0, &out_bits); + + assert(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); + assert(out_bits == 0); + assertError(bit_stream_le.readBitsNoEof(u1, 1), error.EndOfStream); } test "BitOutStream" {