Skip to content

Segmentation fault on accessing fields of tagged unions #18518

Description

@timfayz

Zig Version

0.12.0-dev.2127+fcc0c5ddc

Steps to Reproduce and Observed Behavior

const std = @import("std");

const Union = union(enum) {
    Foo: u8,
    Bar: f64,
};

pub fn main() !void {
    std.log.debug("{any}", .{Union.Foo});
}

Gives:

zig run bugAccessTaggedUnion.zig 
LLVM Emit Object... zsh: segmentation fault  zig run bugAccessTaggedUnion.zig

System: MacOS Monterey, 12.0.1, Apple M1

Expected Behavior

Using @compilerLog(Union.Foo) instead, gives:

@as(@typeInfo(bugAccessTaggedUnion.Union).Union.tag_type.?, .Foo)

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.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