update filesize -> filesize math to fix coercion errors (#3675)

* update filesize -> filesize math to fix coercion errors

* maybe shouldn't do some operations with filesize and int?
This commit is contained in:
Darren Schroeder 2021-06-23 15:37:20 -05:00 committed by GitHub
parent 104cf5b51b
commit a1aae8ca38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,11 +113,21 @@ pub fn compute_values(
let result = match operator { let result = match operator {
Operator::Plus => Ok(x + y), Operator::Plus => Ok(x + y),
Operator::Minus => Ok(x - y), Operator::Minus => Ok(x - y),
Operator::Multiply => Ok(x * y),
Operator::Divide => {
if y.is_zero() {
Err((left.type_name(), right.type_name()))
} else {
Ok(x / y)
}
}
_ => Err((left.type_name(), right.type_name())), _ => Err((left.type_name(), right.type_name())),
}?; }?;
Ok(UntaggedValue::Primitive(Primitive::Filesize(result))) Ok(UntaggedValue::Primitive(Primitive::Filesize(result)))
} }
(Primitive::Filesize(x), Primitive::Int(y)) => match operator { (Primitive::Filesize(x), Primitive::Int(y)) => match operator {
// Operator::Plus => Ok(UntaggedValue::Primitive(Primitive::Filesize(x + *y as u64))),
// Operator::Minus => Ok(UntaggedValue::Primitive(Primitive::Filesize(x - *y as u64))),
Operator::Multiply => { Operator::Multiply => {
Ok(UntaggedValue::Primitive(Primitive::Filesize(x * *y as u64))) Ok(UntaggedValue::Primitive(Primitive::Filesize(x * *y as u64)))
} }
@ -127,9 +137,14 @@ pub fn compute_values(
_ => Err((left.type_name(), right.type_name())), _ => Err((left.type_name(), right.type_name())),
}, },
(Primitive::Int(x), Primitive::Filesize(y)) => match operator { (Primitive::Int(x), Primitive::Filesize(y)) => match operator {
// Operator::Plus => Ok(UntaggedValue::Primitive(Primitive::Filesize(*x as u64 + y))),
// Operator::Minus => Ok(UntaggedValue::Primitive(Primitive::Filesize(*x as u64 - y))),
Operator::Multiply => { Operator::Multiply => {
Ok(UntaggedValue::Primitive(Primitive::Filesize(*x as u64 * y))) Ok(UntaggedValue::Primitive(Primitive::Filesize(*x as u64 * y)))
} }
// Operator::Divide => {
// Ok(UntaggedValue::Primitive(Primitive::Filesize(*x as u64 / y)))
// }
_ => Err((left.type_name(), right.type_name())), _ => Err((left.type_name(), right.type_name())),
}, },
(Primitive::Int(x), Primitive::Int(y)) => match operator { (Primitive::Int(x), Primitive::Int(y)) => match operator {