Zig Version
0.10.0
Steps to Reproduce and Observed Behavior
I've encountered this issue while working on a protobuf implementation. The following is the smallest repro i can make. Setting oom_trigger = false allows the program to compile and the test segfaults as expected. The problem seems to be related to using the io.limitedReader() (possibly related to error the error set analysis?). Its strange to me that this only happens after introducing the io.limitedReader().
// /tmp/test.zig
const std = @import("std");
const Allocator = std.mem.Allocator;
pub const Error = error{ Overflow, EndOfStream };
const oom_trigger = true;
const A = struct {
b: *B = undefined,
fn deserialize(self: *A, allocator: Allocator, reader: anytype) Error!void {
try self.b.deserialize(allocator, reader);
}
};
const B = struct {
a: *A = undefined,
fn deserialize(self: *B, allocator: Allocator, reader: anytype) Error!void {
if (oom_trigger) {
var limreader = std.io.limitedReader(reader, 1);
try self.a.deserialize(allocator, limreader.reader());
} else {
try self.a.deserialize(allocator, reader);
}
}
};
test {
var x: A = .{};
var fbs = std.io.fixedBufferStream("\xFF\xFF\xFF\x00");
try x.deserialize(undefined, fbs.reader());
}
$ zig version
0.10.0
$ zig test /tmp/test.zig
Semantic Analysis [10882] readByte... ^C
# Note: I've killed the program here with ctrl+c
possibly related to #4572
Expected Behavior
the test should compile and segfault due to infinite recursion (a.deserialize() -> b.deserialize() -> a.deserialize() ...).
Zig Version
0.10.0
Steps to Reproduce and Observed Behavior
I've encountered this issue while working on a protobuf implementation. The following is the smallest repro i can make. Setting
oom_trigger = falseallows the program to compile and the test segfaults as expected. The problem seems to be related to using theio.limitedReader()(possibly related to error the error set analysis?). Its strange to me that this only happens after introducing theio.limitedReader().possibly related to #4572
Expected Behavior
the test should compile and segfault due to infinite recursion (a.deserialize() -> b.deserialize() -> a.deserialize() ...).