Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested @max intrinsic calls attempt to cast comptime_ints to u6 #15776

Closed
Validark opened this issue May 19, 2023 · 1 comment · Fixed by #15797
Closed

nested @max intrinsic calls attempt to cast comptime_ints to u6 #15776

Validark opened this issue May 19, 2023 · 1 comment · Fixed by #15797
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@Validark
Copy link
Contributor

Zig Version

0.11.0-dev.3206+b9d2e0e30

Steps to Reproduce and Observed Behavior

const std = @import("std");

const a = 12;
const b = 32;

pub fn main() void {
    const x = @max(std.math.maxInt(u8), @max(a, b));
    _ = x;
}

output:

src/a.zig:7:35: error: type 'u6' cannot represent integer value '255'
    const x = @max(std.math.maxInt(u8), @max(a, b));
                   ~~~~~~~~~~~~~~~^~~~

Expected Behavior

x should be @as(comptime_int, 255)

@Validark Validark added the bug Observed behavior contradicts documented or intended behavior label May 19, 2023
@mlugg
Copy link
Member

mlugg commented May 20, 2023

Caused by PTR of uX and comptime_int always returning uX, even if that type isn't large enough for the comptime_int. Smaller repro: _ = @max(2, @as(u1, 1)) or even just _ = 2 + @as(u1, 1). Resolution is to change @min/@max to return a comptime_int if all arguments are comptime_int.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants