Skip to content

Tagged union in struct is not initialized correctly #4295

@Vexu

Description

@Vexu
const Value = struct {
    ref: u32 = 2, // commenting works
    kind: union(enum) {
        // any of these 3 work
        // None,
        // None: bool,
        // None: u32,
        None: usize,
        Bool: bool,
    },
};
test "" {
    // using const here works
    var True = Value{
        .kind = .{ .Bool = true },
    };
    assert(True.ref == 2);
    assert(True.kind.Bool);
}
Test [1/1] test ""...access of inactive union field
./test.zig:32:21: 0x206751 in test "" (test)
    assert(True.kind.Bool);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.stage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions