#block bug, value left uninitialized

1 messages · Page 1 of 1 (latest)

tiny mulch
#

is this filed already?

pub fn main() void {
    const item: U = blk: {
        var t: usize = 0;
        _ = &t;

        if (t == 100) {
            break :blk .{ .a = 12345 };
        }
    };
    std.log.info("{}", .{item});
}

const U = struct { a: u32 = 0 };

output:

% zig run src/main.zig
info: main.U{ .a = 16777216 }

changing the if statement to

if (false) {
    break :blk .{ .a = 12345 };
}

outputs:

% zig run src/main.zig
src/main.zig:12:26: error: comptime dereference requires 'main.U' to have a well-defined layout
    std.log.info("{}", .{item});
                         ^~~~
src/main.zig:15:11: note: struct declared here
const U = struct { a: u32 = 0 };
          ^~~~~~~~~~~~~~~~~~~~~

this reproduces on master, 0.13.0, 0.12.0, am i missing something?

boreal trout
#

huh

#

the bug here is that we reach the end of the block without breaking out of it

tiny mulch
#

yeah, usually zig can catch that

boreal trout
#

it needs to, for this exact reason

#

i dont know of an issue like this

tiny mulch
#

ok so its something to do with anonymous structs because if you change it to:

    const item = blk: {
        var t: usize = 1;
        _ = &t;

        if (t == 100) {
            break :blk U{ .a = 12345 };
        }
    };

it catches it:

% zig run src/main.zig                                                                                                                                              1 ↵
src/main.zig:4:23: error: incompatible types: 'main.U' and 'void'
    const item = blk: {
                 ~~~~~^
src/main.zig:9:25: note: type 'main.U' here
            break :blk U{ .a = 12345 };
                       ~^~~~~~~~~~~~~~
boreal trout
#

yeah

#

interesting

tiny mulch
#

ill look thru the issues and if i cant find it i'll file