Skip to content

packed struct/union bit casting panics #14268

@leighmcculloch

Description

@leighmcculloch

Zig Version

0.11.0-dev.1265+3ab43988c

Steps to Reproduce and Observed Behavior

pub const Val = packed struct {
    const Self = @This();

    isTagged: bool,
    body: packed union {
        u63: u63,
        tagged: packed union {
            tags: enum(u3) {
                u32 = 0,
                i32 = 1,
                static = 2,
                object = 3,
                symbol = 4,
                bitSet = 5,
                status = 6,
            },
            body: packed union {
                static: enum(u60) {
                    void = 0,
                    true = 1,
                    false = 2,
                },
            },
        },
    },
};

const v: Val = @bitCast(Val, @as(u64, 2));
thread 2478416 panic: TODO implement readFromPackedMemory for more types

Expected Behavior

I expected to be able to bit cast from a u64 to a Val, which is a 64-bit sized packed struct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions