Matched on i64::checked_abs and changed RuntimeError to IntegerOverflow

This commit is contained in:
krishvishal 2025-01-29 22:34:19 +05:30
parent 84d47eb582
commit f8c1828ddf
2 changed files with 6 additions and 10 deletions

View file

@ -45,8 +45,8 @@ pub enum LimboError {
ExtensionError(String),
#[error("Unbound parameter at index {0}")]
Unbound(NonZero<usize>),
#[error("Runtime error: {0}")]
RuntimeError(String),
#[error("Runtime error: integer overflow")]
IntegerOverflow,
}
#[macro_export]

View file

@ -2708,15 +2708,11 @@ pub fn exec_soundex(reg: &OwnedValue) -> OwnedValue {
fn exec_abs(reg: &OwnedValue) -> Result<OwnedValue> {
match reg {
OwnedValue::Integer(x) => {
if *x == i64::MIN {
match i64::checked_abs(*x) {
Some(y) => Ok(OwnedValue::Integer(y)),
// Special case: if we do the abs of "-9223372036854775808", it causes overflow.
// return RuntimeError
return Err(LimboError::RuntimeError("integer overflow".to_string()));
}
if x < &0 {
Ok(OwnedValue::Integer(-x))
} else {
Ok(OwnedValue::Integer(*x))
// return IntegerOverflow error
None => Err(LimboError::IntegerOverflow),
}
}
OwnedValue::Float(x) => {