Skip to content

Commit 65b0f0f

Browse files
committed
raise exception when long overflows
1 parent ffb3f61 commit 65b0f0f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonLongExports.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4444
import com.oracle.graal.python.builtins.objects.ints.PInt;
4545
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
46+
import com.oracle.graal.python.nodes.PRaiseNode;
47+
import com.oracle.truffle.api.dsl.Cached;
4648
import com.oracle.truffle.api.dsl.Specialization;
4749
import com.oracle.truffle.api.library.ExportLibrary;
4850
import com.oracle.truffle.api.library.ExportMessage;
@@ -67,11 +69,12 @@ static int noOverflow(Long self) {
6769
}
6870

6971
@Specialization(replaces = "noOverflow")
70-
static int withOverflow(Long self) {
72+
static int withOverflow(Long self,
73+
@Cached PRaiseNode raise) {
7174
try {
7275
return PInt.intValueExact(self);
7376
} catch (ArithmeticException e) {
74-
return -1;
77+
throw raise.raise(PythonBuiltinClassType.OverflowError, "cannot fit '%p' into an index-sized integer", self);
7578
}
7679
}
7780
}

0 commit comments

Comments
 (0)