Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal compiler error assigning tagged union #22393

Open
sjb3d opened this issue Jan 2, 2025 · 2 comments
Open

Internal compiler error assigning tagged union #22393

sjb3d opened this issue Jan 2, 2025 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@sjb3d
Copy link
Contributor

sjb3d commented Jan 2, 2025

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

I have been getting internal compiler errors on Zig 0.13.0, managed to reduce to a small repro case assigning a value to a struct that has a tagged union field:

var outer: Outer = undefined;

const Outer = struct {
    a: i32,
    b: u32,
    c: Inner,

    const Inner = union(enum) {
        none: void,
        something: u32,
    };
};

export fn foo() void {
    outer = .{
        .a = 0,
        .b = 1,
        .c = .{ .none = {} },
        //.c = Outer.Inner{ .none = {} },
    };
}

On godbolt this produces the following compiler output from both 0.13.0 and trunk (0.14.0-dev.2589+0df1f3df2):

Program terminated with signal: SIGTRAP
Compiler returned: 133

Interestingly, if I uncomment the alternative assignment for c above that uses an explicit type, then compilation succeeds. I am using this workaround with my own project for now too.

Expected Behavior

Compilation succeeds in the original code where the type is omitted.

@sjb3d sjb3d added the bug Observed behavior contradicts documented or intended behavior label Jan 2, 2025
@Rexicon226
Copy link
Contributor

duplicate of #19832

@sjb3d
Copy link
Contributor Author

sjb3d commented Jan 2, 2025

Doh my search-fu failed me, please feel free to close in favour of the original report.

Would be great to fix this in the front-end if possible, as it is not clear at all for the end user what is causing the compiler error!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants