Fixed comparison between bytes and decimals

The previous commit introduced a new decimal type as well as comparison
coercions between decimals and integers, but not between decimals and
bytes.
This commit is contained in:
Yehuda Katz 2019-08-30 16:37:23 -07:00
parent 138b5af82b
commit 6f5ddbd6ae

View File

@ -829,11 +829,17 @@ fn coerce_compare_primitive(
Ok(match (left, right) {
(Int(left), Int(right)) => CompareValues::Ints(*left, *right),
(Decimal(left), Decimal(right)) => CompareValues::Decimals(*left, *right),
(Decimal(left), Int(right)) => CompareValues::Decimals(*left, (*right).into()),
(Int(left), Decimal(right)) => CompareValues::Decimals((*left).into(), *right),
(Int(left), Bytes(right)) => CompareValues::Bytes(*left as u64, *right),
(Decimal(left), Decimal(right)) => CompareValues::Decimals(*left, *right),
(Decimal(left), Int(right)) => CompareValues::Decimals(*left, (*right).into()),
(Decimal(left), Bytes(right)) => {
CompareValues::Decimals(*left, rust_decimal::Decimal::from(*right))
}
(Bytes(left), Int(right)) => CompareValues::Bytes(*left, *right as u64),
(Bytes(left), Decimal(right)) => {
CompareValues::Decimals(rust_decimal::Decimal::from(*left), *right)
}
(String(left), String(right)) => CompareValues::String(left.clone(), right.clone()),
_ => return Err((left.type_name(), right.type_name())),
})