Skip to content

segfault when accidentally calling a tagged union field #18546

@travisstaloch

Description

@travisstaloch

Zig Version

0.12.0-dev.2158+4f2009de1

Steps to Reproduce and Observed Behavior

When I accidentally used a field name as a method it caused the compiler to segfault:

// /tmp/tmp.zig
const U = union(enum) {
    int: isize,
    float: f64,
};
test {
    const f = U{ .float = 20 };
    std.debug.print("{}\n", .{f.int()});
}
/tmp $ zig test /tmp/tmp.zig
Segmentation fault (core dumped)

Expected Behavior

some kind of error message and no segfault

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