Skip to content

Commit 0a2fe02

Browse files
committed
Raise the compile() unrecognised-flags error with its message
checkFlags called PRaiseNode.raiseStatic(this, ValueError, null, NO_VALUE, UNRECOGNIZED_FLAGS, EMPTY_OBJECT_ARRAY), mirroring the argument order of the old internal execute(). No public overload takes those arguments, so the call bound to raiseStatic(Node, type, message, Object...) with a null message and the intended message as a format argument. The ValueError could be caught, but str(), repr() or .args on it formatted the null message and threw a Java NullPointerException. Use the message overload, as checkOptimize next to it does. CPython raises ValueError("compile(): unrecognised flags"). Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
1 parent 7e7182b commit 0a2fe02

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎graalpython/com.oracle.graal.python.test/src/tests/test_parser.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ def test_incomplete_input_error():
6464
assert False, "SyntaxError was not raised"
6565

6666

67+
def test_compile_unrecognised_flags_message():
68+
try:
69+
compile("1", "<input>", "exec", 0x7fffffff)
70+
except ValueError as e:
71+
assert str(e) == "compile(): unrecognised flags"
72+
else:
73+
assert False, "ValueError was not raised"
74+
75+
6776
def test_lambdas_as_function_default_argument_values():
6877
globs = {}
6978
exec("""

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ private void checkOptimize(int optimize, Object kwOptimize) throws PException {
11431143
@TruffleBoundary
11441144
private void checkFlags(int flags) {
11451145
if ((flags & ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_COMPILE_MASK)) != 0) {
1146-
throw PRaiseNode.raiseStatic(this, ValueError, null, NO_VALUE, ErrorMessages.UNRECOGNIZED_FLAGS, PythonUtils.EMPTY_OBJECT_ARRAY);
1146+
throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.UNRECOGNIZED_FLAGS);
11471147
}
11481148
}
11491149

0 commit comments

Comments
 (0)