lang: Compare folded unsigned integers correctly

9913dc8b45f32b419e5780683ed1f2ce3d295b558deaab6fa94f5d04461f578f
Unsigned constants above the signed 64-bit maximum were compared through
an i64 conversion, so ordered constant expressions produced reversed
results.

Use the original unsigned magnitudes for ordered comparisons unless
either operand is signed.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent 988225b7
lib/std/lang/resolver.rad +8 -4
6326 6326
                magnitude: left.magnitude >> right.magnitude, bits, signed, negative: left.negative,
6327 6327
            });
6328 6328
        },
6329 6329
        case ast::BinaryOp::Eq  => return ConstValue::Bool(l == r),
6330 6330
        case ast::BinaryOp::Ne  => return ConstValue::Bool(l <> r),
6331 -
        case ast::BinaryOp::Lt  => return ConstValue::Bool(l < r),
6332 -
        case ast::BinaryOp::Gt  => return ConstValue::Bool(l > r),
6333 -
        case ast::BinaryOp::Lte => return ConstValue::Bool(l <= r),
6334 -
        case ast::BinaryOp::Gte => return ConstValue::Bool(l >= r),
6331 +
        case ast::BinaryOp::Lt =>
6332 +
            return ConstValue::Bool(l < r if signed else left.magnitude < right.magnitude),
6333 +
        case ast::BinaryOp::Gt =>
6334 +
            return ConstValue::Bool(l > r if signed else left.magnitude > right.magnitude),
6335 +
        case ast::BinaryOp::Lte =>
6336 +
            return ConstValue::Bool(l <= r if signed else left.magnitude <= right.magnitude),
6337 +
        case ast::BinaryOp::Gte =>
6338 +
            return ConstValue::Bool(l >= r if signed else left.magnitude >= right.magnitude),
6335 6339
        case ast::BinaryOp::Add => return ConstValue::Int(constIntFromSigned(l + r, bits, signed)),
6336 6340
        case ast::BinaryOp::Sub => return ConstValue::Int(constIntFromSigned(l - r, bits, signed)),
6337 6341
        case ast::BinaryOp::Mul => return ConstValue::Int(constIntFromSigned(l * r, bits, signed)),
6338 6342
        case ast::BinaryOp::Div => {
6339 6343
            if r == 0 {
test/tests/const.u64.compare.rad added +11 -0
1 +
//! returns: 0
2 +
3 +
constant LARGE: u64 = 0xffffffffffffffff;
4 +
constant IS_POSITIVE: bool = LARGE > 0;
5 +
6 +
@default fn main() -> i32 {
7 +
    if IS_POSITIVE {
8 +
        return 0;
9 +
    }
10 +
    return 1;
11 +
}