Skip to content

Compiler crash on comptime var assginment with tagged union #19516

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

Open
vancluever opened this issue Apr 2, 2024 · 3 comments
Open

Compiler crash on comptime var assginment with tagged union #19516

vancluever opened this issue Apr 2, 2024 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@vancluever
Copy link

Zig Version

0.12.0-dev.3518+d2be725e4

Steps to Reproduce and Observed Behavior

The following code will cause SIGTRAP on zig build. The repro was set up off of the zig init scaffolding:

const std = @import("std");

const A = struct {
    a: i32,
};

const B = struct {
    a: i32,
};

const AB_type = enum {
    a,
    b,
};

const AB = union(AB_type) {
    a: A,
    b: B,
};

pub fn main() !void {
    comptime var foo: AB = .{ .a = .{ .a = 32 } };
    std.debug.print("{d}\n", .{foo.a.a});
    foo = .{ .a = .{ .a = 64 } };
    std.debug.print("{d}\n", .{foo.a.a});
}

Removing the comptime from the comptime var assignment fixes things, allowing the build/run to succeed.

Expected Behavior

Build should succeed, or tell me why what I am doing is a bad idea and/or not allowed. In the real world situation where this came up, I think for some reason the compiler used to be telling me that the union needed to be comptime, even though I probably just needed to add a type to it or something else. 😉

@vancluever vancluever added the bug Observed behavior contradicts documented or intended behavior label Apr 2, 2024
@mlugg
Copy link
Member

mlugg commented Apr 3, 2024

Likely related to #19452 - this example should be tested when that branch is complete.

@vancluever
Copy link
Author

@mlugg if it helps, I did roll back to 0.12.0-dev.3405+31791ae15 during troubleshooting, which helped surface some of the errors (I think that re-assignment here actually caused a full-on segfault). 0.12.0-dev.2811+3cafb9655 was working completely without errors.

@Vexu
Copy link
Member

Vexu commented Apr 3, 2024

Related #19511

@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Apr 3, 2024
@Vexu Vexu added this to the 0.13.0 milestone Apr 3, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 10, 2025
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

4 participants