Skip to content

Segfault with tagged union #8189

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

Closed
lxn opened this issue Mar 9, 2021 · 1 comment
Closed

Segfault with tagged union #8189

lxn opened this issue Mar 9, 2021 · 1 comment
Milestone

Comments

@lxn
Copy link

lxn commented Mar 9, 2021

Using Zig from zig-windows-x86_64-0.8.0-dev.1431+c760532be.zip on Windows 10.

const std = @import("std");

pub fn main() void {
    const b1 = Baz{ .quux = 1 };
    std.debug.print("1: {}\n", .{Foo{ .baz = b1 }});

    const b2 = Baz.init(2);
    std.debug.print("2: {}\n", .{Foo{ .baz = b2 }});
}

const Foo = union(enum) {
    bar: i32,
    baz: Baz,
};

const Baz = struct {
    quux: i32,

    pub fn init(the_quux: i32) @This() {
        return .{ .quux = the_quux };
    }
};

Output:

1: Foo{ .baz = Baz{ .quux = 1 } }
Segmentation fault at address 0x7ff6afd7c5e8
C:\devel\Zig\projects\playground\union_segfault_repro\src\main.zig:8:39: 0x7ff6afd430ce in main (union_segfault_repro.obj)
    std.debug.print("2: {}\n", .{Foo{ .baz = b2 }});
                                      ^
C:\devel\Zig\zig-windows-x86_64\lib\zig\std\start.zig:174:65: 0x7ff6afd41a87 in std.start.WinStartup (union_segfault_repro.obj)
    std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain());
                                                                ^
@Vexu
Copy link
Member

Vexu commented Mar 9, 2021

Duplicate of #3915.

@Vexu Vexu closed this as completed Mar 9, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants