Skip to content

Commit db64f90

Browse files
committed
CastToJavaLongExactNode should throw OverflowError not TypeError
1 parent 5853489 commit db64f90

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongExactNode.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@
4040
*/
4141
package com.oracle.graal.python.nodes.util;
4242

43-
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
43+
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError;
44+
4445
import com.oracle.graal.python.builtins.objects.ints.PInt;
4546
import com.oracle.graal.python.nodes.ErrorMessages;
4647
import com.oracle.graal.python.nodes.PRaiseNode;
4748
import com.oracle.graal.python.util.OverflowException;
48-
import com.oracle.truffle.api.CompilerDirectives;
49+
import com.oracle.truffle.api.dsl.Cached;
4950
import com.oracle.truffle.api.dsl.GenerateUncached;
5051
import com.oracle.truffle.api.dsl.Specialization;
5152

@@ -64,13 +65,18 @@ public static CastToJavaLongExactNode getUncached() {
6465
return CastToJavaLongExactNodeGen.getUncached();
6566
}
6667

67-
@Specialization
68-
protected long toLong(PInt x) {
68+
@Specialization(rewriteOn = OverflowException.class)
69+
protected static long toLongNoOverflow(PInt x) throws OverflowException {
70+
return x.longValueExact();
71+
}
72+
73+
@Specialization(replaces = "toLongNoOverflow")
74+
protected static long toLong(PInt x,
75+
@Cached PRaiseNode raiseNode) {
6976
try {
7077
return x.longValueExact();
7178
} catch (OverflowException e) {
72-
CompilerDirectives.transferToInterpreter();
73-
throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.CANNOT_BE_INTEPRETED_AS_LONG, x, x);
79+
throw raiseNode.raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "long");
7480
}
7581
}
7682
}

0 commit comments

Comments
 (0)