Skip to content

x: Type parameter is mistaken as anytype parameter #16663

@ghost

Description

Zig Version

0.11.0-dev.4404+4f6013bf5

Steps to Reproduce and Observed Behavior

Probably a duplicate but

test {
    writeIntLittle(u64, @bitCast(packed struct { hi: u32, lo: u32 }{ .hi = 0, .lo = 0 }));
}

fn writeIntLittle(comptime Type: type, x: Type) void {
    _ = x;
}
$ zig test x.zig
x.zig:2:25: error: @bitCast must have a known result type
    writeIntLittle(u64, @bitCast(packed struct { hi: u32, lo: u32 }{ .hi = 0, .lo = 0 }));
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x.zig:2:25: note: result type is unknown due to anytype parameter
x.zig:2:25: note: use @as to provide explicit result type

Expected Behavior

Test passes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions