Fix handling of Lt, LtEq (#393)

Changed the middleware to only allow comparison of integers and to
use the implementation of Ord for i64.  This matches the backend
behavior.

Also fixed a separate bug where LtEqFromEntries was producing a
NotEquals statement.
This commit is contained in:
Daniel Gulotta 2025-08-18 07:54:20 -07:00 committed by GitHub
parent 1508dd6126
commit f76197c602
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 36 additions and 27 deletions

View file

@ -408,8 +408,8 @@ impl MainPodBuilder {
}
}
(LtFromEntries, &[a1, a2]) => {
let (r1, v1) = a1.value_and_ref().ok_or_else(native_arg_error)?;
let (r2, v2) = a2.value_and_ref().ok_or_else(native_arg_error)?;
let (r1, v1) = a1.int_value_and_ref().ok_or_else(native_arg_error)?;
let (r2, v2) = a2.int_value_and_ref().ok_or_else(native_arg_error)?;
if v1 < v2 {
Statement::lt(r1, r2)
} else {
@ -417,10 +417,10 @@ impl MainPodBuilder {
}
}
(LtEqFromEntries, &[a1, a2]) => {
let (r1, v1) = a1.value_and_ref().ok_or_else(native_arg_error)?;
let (r2, v2) = a2.value_and_ref().ok_or_else(native_arg_error)?;
let (r1, v1) = a1.int_value_and_ref().ok_or_else(native_arg_error)?;
let (r2, v2) = a2.int_value_and_ref().ok_or_else(native_arg_error)?;
if v1 <= v2 {
Statement::not_equal(r1, r2)
Statement::lt_eq(r1, r2)
} else {
return Err(native_arg_error());
}

View file

@ -4,7 +4,7 @@ use crate::{
frontend::{MainPod, SignedPod},
middleware::{
AnchoredKey, CustomPredicateRef, NativeOperation, OperationAux, OperationType, Statement,
Value, ValueRef,
TypedValue, Value, ValueRef,
},
};
@ -33,6 +33,13 @@ impl OperationArg {
_ => None,
}
}
pub(crate) fn int_value_and_ref(&self) -> Option<(ValueRef, i64)> {
self.value_and_ref().and_then(|(r, v)| match v.typed() {
&TypedValue::Int(i) => Some((r, i)),
_ => None,
})
}
}
impl fmt::Display for OperationArg {