Skip to content

Integer coercion consideres non-type bits #11263

Description

@ikskuh

Zig Version

0.10.0-dev.1261+6f986298c

Steps to Reproduce

const std = @import("std");

pub fn main() !void  {
    var value: u4 = undefined;
    std.debug.print("u4={}, usize={}\n", .{
        value,
        @as(usize, value),
    });
}

Expected Behavior

Code prints

u4=10, usize=10

Actual Behavior

Code prints

u4=10, usize=170

It looks like the compiler is assuming that the upper bits of a u4 are 0, which doesn't happen when unitializing to undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions