Fixed zero division and zero assertion errors when [] / 0

trunk
ondra05 2022-05-04 23:15:12 +02:00
parent 3e8cffe1a5
commit 85eefeb953
1 changed files with 9 additions and 2 deletions

View File

@ -760,8 +760,15 @@ impl ops::Div for Value {
}
}),
Value::Cart(c) => {
let cart_len = c.len();
let chunk_len = rhs.into_isize() as usize;
let cart_len = match c.len() {
0 => return Value::Cart(HashMap::new()),
l => l,
};
let chunk_len = match rhs.into_isize() as usize {
0 => rand::thread_rng().gen_range(1..=cart_len),
l => l,
};
Value::Cart(
c.into_iter()