#error code 5 with comptime stack and optionals

1 messages · Page 1 of 1 (latest)

fluid arch
#

I get error code 5 with this code, why does this happen?

const std = @import("std");

fn ComptimeStack(comptime T: type) type {
    return struct {
        array: []T,

        pub inline fn init() @This() {
            return .{ .array = &.{} };
        }

        pub inline fn push(comptime self: *@This(), item: T) !void {
            var a = (self.array ++ .{item}).*;
            self.array = &a;
        }
    };
}

pub fn main() void {
    comptime var stack = ComptimeStack(struct { u32, ?struct { val: u8 } }).init();
    comptime try stack.push(.{420, null});
    std.mem.doNotOptimizeAway(stack);
}
#

zig 0.12.0-dev.2063+804cee3b9

naive girder
#

i got it to run with this 1 change:

pub inline fn push(self: *@This(), item: T) !void {

EDITED

#

not sure why it segfaulted otherwise, but if you can make a reduced test case which reproduces the segfault, i think you should open an issue.

fluid arch
#

it seems that passing null or undefined would crash it