Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6c8584c

Browse files
Merge pull requestRustPython#564 from alexpantyukhin/int_shifts
add overflow errors for int shifts.
2 parents9404c7c +70ad78e commit6c8584c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

‎tests/snippets/ints.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtestutilsimportassert_raises
2+
13
# int to int comparisons
24

35
assert1==1
@@ -36,6 +38,7 @@
3638
assert (1).real==1
3739
assert (1).imag==0
3840

41+
assert_raises(OverflowError,lambda:1<<10**100000)
3942

4043
assert (1).__eq__(1.0)==NotImplemented
4144
assert (1).__ne__(1.0)==NotImplemented

‎vm/src/obj/objint.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ fn int_lshift(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
246246
matchget_value(i2){
247247
ref vif*v <BigInt::zero() =>Err(vm.new_value_error("negative shift count".to_string())),
248248
ref vif*v >BigInt::from(usize::max_value()) =>{
249-
// TODO: raise OverflowError
250-
panic!("Failed converting {} to rust usize", get_value(i2));
249+
Err(vm.new_overflow_error("the number is too large to convert to int".to_string()))
251250
}
252251
_ =>panic!("Failed converting {} to rust usize", get_value(i2)),
253252
}
@@ -276,8 +275,7 @@ fn int_rshift(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
276275
matchget_value(i2){
277276
ref vif*v <BigInt::zero() =>Err(vm.new_value_error("negative shift count".to_string())),
278277
ref vif*v >BigInt::from(usize::max_value()) =>{
279-
// TODO: raise OverflowError
280-
panic!("Failed converting {} to rust usize", get_value(i2));
278+
Err(vm.new_overflow_error("the number is too large to convert to int".to_string()))
281279
}
282280
_ =>panic!("Failed converting {} to rust usize", get_value(i2)),
283281
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp