diff --git a/std/io.zig b/std/io.zig index 499422fdcc..5f710a5033 100644 --- 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 index 430c8f135a..ed8e0fcadb 100644 --- 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" {