Skip to content

peekByte() on std.Io.Reader.failing triggers an assertion failure #25199

@generalmimon

Description

@generalmimon

Zig Version

0.15.1

Steps to Reproduce and Observed Behavior

Calling peekByte() on std.Io.Reader.failing causes an assertion failure in the standard library.

Reproduction code:

const std = @import("std");
const testing = std.testing;

test "std.Io.Reader.failing.peekByte() should return error.ReadFailed" {
    var r = std.Io.Reader.failing;
    try testing.expectError(error.ReadFailed, r.peekByte());
}

Console output:

$ zig-x86_64-linux-0.15.1/zig test test.zig
thread 187 panic: reached unreachable code
/home/pp/zig-x86_64-linux-0.15.1/lib/std/debug.zig:559:14: 0x102e3e9 in assert (std.zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/pp/zig-x86_64-linux-0.15.1/lib/std/Io/Reader.zig:1250:11: 0x102d3cd in defaultRebase (std.zig)
    assert(r.buffer.len - r.seek >= capacity);
          ^
/home/pp/zig-x86_64-linux-0.15.1/lib/std/Io/Reader.zig:1241:27: 0x1071559 in rebase (std.zig)
    return r.vtable.rebase(r, capacity);
                          ^
/home/pp/zig-x86_64-linux-0.15.1/lib/std/Io/Reader.zig:1026:15: 0x104b5a1 in fillUnbuffered (std.zig)
    try rebase(r, n);
              ^
/home/pp/zig-x86_64-linux-0.15.1/lib/std/Io/Reader.zig:1014:26: 0x10301ff in fill (std.zig)
    return fillUnbuffered(r, n);
                         ^
/home/pp/zig-x86_64-linux-0.15.1/lib/std/Io/Reader.zig:1054:13: 0x102d6f2 in peekByte (std.zig)
    try fill(r, 1);
            ^
/home/pp/test.zig:6:57: 0x102c1a7 in test.std.Io.Reader.failing.peekByte() should return error.ReadFailed (test.zig)
    try testing.expectError(error.ReadFailed, r.peekByte());
                                                        ^
/home/pp/zig-x86_64-linux-0.15.1/lib/compiler/test_runner.zig:218:25: 0x115dd80 in mainTerminal (test_runner.zig)
        if (test_fn.func()) |_| {
                        ^
/home/pp/zig-x86_64-linux-0.15.1/lib/compiler/test_runner.zig:66:28: 0x1156fa1 in main (test_runner.zig)
        return mainTerminal();
                           ^
/home/pp/zig-x86_64-linux-0.15.1/lib/std/start.zig:618:22: 0x1150d3d in posixCallMainAndExit (std.zig)
            root.main();
                     ^
/home/pp/zig-x86_64-linux-0.15.1/lib/std/start.zig:232:5: 0x11505d1 in _start (std.zig)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
error: the following test command crashed:
.cache/zig/o/cfa6149a05a5b2438e887ac7db257da8/test --seed=0x57fc642c

Expected Behavior

I expected that all operations on std.Io.Reader.failing would return error.ReadFailed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions