add overflow errors for int shifts.

This commit is contained in:
alexpantyukhin
2019-02-27 11:04:16 +04:00
parent d6242ac6e3
commit 15e6187583
2 changed files with 5 additions and 4 deletions

View File

@@ -246,8 +246,7 @@ fn int_lshift(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
match get_value(i2) {
ref v if *v < BigInt::zero() => Err(vm.new_value_error("negative shift count".to_string())),
ref v if *v > BigInt::from(usize::max_value()) => {
// TODO: raise OverflowError
panic!("Failed converting {} to rust usize", get_value(i2));
Err(vm.new_overflow_error("the number is too large to convert to float".to_string()))
}
_ => panic!("Failed converting {} to rust usize", get_value(i2)),
}
@@ -276,8 +275,7 @@ fn int_rshift(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
match get_value(i2) {
ref v if *v < BigInt::zero() => Err(vm.new_value_error("negative shift count".to_string())),
ref v if *v > BigInt::from(usize::max_value()) => {
// TODO: raise OverflowError
panic!("Failed converting {} to rust usize", get_value(i2));
Err(vm.new_overflow_error("the number is too large to convert to float".to_string()))
}
_ => panic!("Failed converting {} to rust usize", get_value(i2)),
}