Skip to content

wrong type inference #19379

Closed
Closed
@dimdin

Description

@dimdin

Zig Version

0.12.0-dev.3381+7057bffc1

Steps to Reproduce and Observed Behavior

To reproduce run:

pub fn main() !void {
    const olength: u32 = 1;
    const precision: ?usize = null;
    const exponent: i32 = -1; 
    const req_bytes = 2 + @max(@abs(exponent) + olength, precision orelse 0);
    _ = req_bytes;
}
❯ zig run test.zig
test.zig:5:25: error: overflow of integer type 'u2' with value '4'
    const req_bytes = 2 + @max(@abs(exponent) + olength, precision orelse 0);
                      ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is an actual library line:

2 + @max(@abs(f.exponent) + olength, precision orelse 0);

It happens only in comptime

Expected Behavior

result type must be u32 or usize instead of u2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions