Skip to content

sema: The builtin function @max/@min support incompatible arbitrary i… #23581

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

flyfish30
Copy link
Contributor

Fixes #23139

In normal arithmatic operations on two or more integer operands, all intergers must be compatible with each other. But in the function @max/@min, this constraint need not be satisfied.

For example, the expression @min(@as(i32, -30), @as(u32, 42)) is a legal expression.

@min/@max functions with two or more arguments have been tested, and @min/@max functions with vector arguments have also been tested.

@flyfish30
Copy link
Contributor Author

@jacobly0 Can you review this PR?

@allocgator
Copy link
Contributor

If this works with isize and usize, could you add a unit test covering it?

…nteger types

In normal arithmatic operations on two or more integer operands, all
intergers must be compatible with each other. But in the function
@max/@min, this constraint need not be satisfied.

For example, the expression `@min(@as(i32, -30), @as(u32, 42))` is a
legal expression.
@flyfish30 flyfish30 force-pushed the fix-min-int-peertypes branch from fa40530 to 7384097 Compare April 17, 2025 00:21
@flyfish30
Copy link
Contributor Author

@jacobly0 Why do the max/min behavior test cases fail only on Linux systems? How can I fix it?

The detail error message is in bellow:

/home/ci/actions-runner9/_work/zig/zig/test/behavior/maximum_minimum.zig:250:9: error: emit MIR failed: InvalidInstruction (Zig compiler bug)
        fn min(lhs: @Vector(2, i16), rhs: @Vector(2, u16)) @Vector(2, i16) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@flyfish30
Copy link
Contributor Author

If this works with isize and usize, could you add a unit test covering it?

The behavior test case has covering i32 and u32 for max/min function, it is enough to verify this issue.

@allocgator
Copy link
Contributor

allocgator commented Apr 17, 2025

The behavior test case has covering i32 and u32 for max/min function, it is enough to verify this issue.

Think of it from a documentation perspective - a unit test with usize and isize would definitely be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sema: incompatible types with @min which is supposed to accept arbitrary integer types
2 participants