I'm trying to run a test for my iterator implementation, and the address of the first item, coming from the Once iterator, for some reason is a pointer with the undefined value. No matter how I initialize it. Here's the source code: https://codeberg.org/DanikVitek/giraphe/src/commit/9914e5fae5d00e420cf4f4787f12c771b715d7d2/lang/src/iter.zig
#`undefined` pointer address (cause: loops have `else` branches)
1 messages · Page 1 of 1 (latest)
instead of screenshots, paste the text between lines with ``` to format them
you can provide a language at the start to control the highlighting, since discord does not support zig we usually use rust or typescript, e.g ```rust
do that for both code and terminal output, it makes it easier to read and copy for our own testing
it is preferable if you paste the relevant code in addition to linking the repo
especially since rn, codeberg is having issues lol
Yes, I'm sorry.
Here's relevant code (edit: poorly higtlightable, so I resent it below without backticks):
And the console output:
error: 'iter.decltest.Chain' terminated with signal ABRT with stderr:
iters is a tuple
Maybe iter: .{ .item = i32@aaaaaaaaaaaaaaaa }
Iter: .{ .item = i32@aaaaaaaaaaaaaaaa }
Item: i32@aaaaaaaaaaaaaaaa
General protection exception (no address available)
/home/danik/.zvm/0.16.0/lib/std/testing.zig:798:52: 0x123a15d in expectEqualDeepInner__anon_43639 (std.zig)
else => try expectEqualDeep(expected.*, actual.*),
^
/home/danik/.zvm/0.16.0/lib/std/testing.zig:741:32: 0x1239650 in expectEqualDeep (std.zig)
return expectEqualDeepInner(T, expected, actual);
^
/home/danik/.zvm/0.16.0/lib/std/testing.zig:741:32: 0x124275b in expectEqualDeep (root.zig)
return expectEqualDeepInner(T, expected, actual);
^
/home/danik/.zvm/0.16.0/lib/compiler/test_runner.zig:140:68: 0x11ed5d7 in mainServer (test_runner.zig)
const status: TestResults.Status = if (test_fn.func()) |v| s: {
^
/home/danik/.zvm/0.16.0/lib/compiler/test_runner.zig:71:26: 0x11ee3fd in main (test_runner.zig)
return mainServer(init) catch |err| panic("internal test runner failure: {t}", .{err});
^
/home/danik/.zvm/0.16.0/lib/std/start.zig:699:88: 0x11eac65 in callMain (std.zig)
if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{
^
/home/danik/.zvm/0.16.0/lib/std/start.zig:190:5: 0x11ea641 in _start (std.zig)
asm volatile (switch (native_arch) {
^
I found the bug, and it seems to be the compiler bug. The Chain's initialization loop did not run when being written as an expression:
pub fn init(iters: Iters) Self {
var opt_iters: OptionalIters = undefined;
if (@typeInfo(Iters) == .array) for (iters, &opt_iters) |i, *oi| {
oi.* = i;
} else inline for (iters, &opt_iters) |i, *oi| {
oi.* = i;
};
return .{ .iters = opt_iters };
}
But this works:
pub fn init(iters: Iters) Self {
var opt_iters: OptionalIters = undefined;
if (@typeInfo(Iters) == .array) {
for (iters, &opt_iters) |i, *oi| {
oi.* = i;
}
} else {
inline for (iters, &opt_iters) |i, *oi| {
oi.* = i;
}
}
return .{ .iters = opt_iters };
}
not a compiler bug, the else was a part of the loop instead of the if.
so when the condition was false the loop did not run at all.
loops can have an else branch that is run when the loop ends, but if you break it wont run
And to be more precise --- the issue is with the inline loop only
ok, that's confusing
