Skip to content

Commit

Permalink
Fix an interesting case where we fail to convert a ctuple to a Python…
Browse files Browse the repository at this point in the history
… tuple on cascaded assignments (test_grammar.py, line 895) because we do not generate a (useless) PyTypeTestNode any more.

Apparently, that type test is still required in order to trigger the Python conversion, which then renders the type test redundant.
  • Loading branch information
scoder committed Aug 26, 2023
1 parent 541299b commit 592c04a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Cython/Compiler/ExprNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,18 @@ def coerce_to(self, dst_type, env):
pass
elif src.constant_result is None:
src = NoneNode(src.pos).coerce_to(dst_type, env)
elif not src.type.is_pyobject:
if dst_type is bytes_type and src.type.is_int:
src = CoerceIntToBytesNode(src, env)
else:
src = CoerceToPyTypeNode(src, env, type=dst_type)
elif not src.type.subtype_of(dst_type):
src = PyTypeTestNode(src, dst_type, env)
else:
if not src.type.is_pyobject:
if dst_type is bytes_type and src.type.is_int:
src = CoerceIntToBytesNode(src, env)
else:
src = CoerceToPyTypeNode(src, env, type=dst_type)
# FIXME: I would expect that CoerceToPyTypeNode(type=dst_type) returns a value of type dst_type
# but it doesn't for ctuples. Thus, we add a PyTypeTestNode which then triggers the
# Python conversion and becomes useless. That sems backwards and inefficient.
# We should not need a PyTypeTestNode after a previous conversion above.
if not src.type.subtype_of(dst_type):
src = PyTypeTestNode(src, dst_type, env)
elif is_pythran_expr(dst_type) and is_pythran_supported_type(src.type):
# We let the compiler decide whether this is valid
return src
Expand Down

0 comments on commit 592c04a

Please sign in to comment.