Skip to content

No error on comptime expression loading runtime value #22296

@jeffective

Description

@jeffective

Zig Version

0.14.0-dev.2540+f857bf72e

Steps to Reproduce and Observed Behavior

Create file test.zig with the following contents:

const std = @import("std");

test {
    var value = @as(u5, 0);
    const Foo = packed struct(u7) {
        val2: u7,
    };
    const foo: Foo = .{ .val2 = value };
    // if `comptime` is removed here, the segfault goes away
    std.debug.print("{}", .{comptime foo});
}

Observe segfault:

$ zig test test.zig 
Segmentation fault

Expected Behavior

Not sure, when I remove the comptime I get the following output:

test.zig:4:9: error: local variable is never mutated
    var value = @as(u5, 0);
        ^~~~~
test.zig:4:9: note: consider using 'const'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions