Skip to content

Commit fdf1329

Browse files
authored
Fix removal of test_node when rhs.current_user_node becomes PyccelAssociativeParenthesis (pyccel#2140)
This PR fixes an issue where attempting to remove `test_node` from `rhs` fails when `rhs.current_user_node` becomes a `PyccelAssociativeParenthesis` during the `operator(lhs, rhs)` operation. This happens when `rhs` contains more than one element, the `operator(lhs, rhs)` call creates a `PyccelAssociativeParenthesis`, which becomes the `current_user_node` of `rhs`. As a result, a direct call to `rhs.remove_user_node(test_node)` fails since `test_node` no longer matches the `current_user_node`.
1 parent ccf5c55 commit fdf1329

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ All notable changes to this project will be documented in this file.
101101
- #2111 : Fix declaration of class attributes with name conflicts using type annotations.
102102
- #2115 : Fix integer handling with NumPy 2.0 on Windows.
103103
- Fix handling of union `typing.TypeAlias` objects as type hints.
104+
- #2141 : Fix error when removing `test_node`
104105

105106
### Changed
106107

pyccel/parser/semantic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3652,7 +3652,12 @@ def _visit_AugAssign(self, expr):
36523652
test_node = None
36533653
if test_node:
36543654
lhs.remove_user_node(test_node, invalidate = False)
3655-
rhs.remove_user_node(test_node, invalidate = False)
3655+
if test_node in rhs.get_all_user_nodes():
3656+
rhs.remove_user_node(test_node, invalidate = False)
3657+
else:
3658+
assert isinstance(rhs.current_user_node, PyccelAssociativeParenthesis)
3659+
mid = rhs.current_user_node
3660+
rhs.remove_user_node(mid, invalidate=False)
36563661
lhs = self._assign_lhs_variable(expr.lhs, self._infer_type(test_node), test_node,
36573662
new_expressions, is_augassign = True)
36583663
lhs = self._optional_params.get(lhs, lhs)

tests/epyccel/test_epyccel_generators.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,12 @@ def f(a0 : 'int[:]'):
198198
f_epyc = epyccel(f, language = language)
199199

200200
assert f(x) == f_epyc(x)
201+
202+
def test_sum_with_two_variables(language):
203+
def f():
204+
x = sum(i-j for i in range(10) for j in range(7))
205+
return x
206+
207+
f_epyc = epyccel(f, language=language)
208+
209+
assert f() == f_epyc()

0 commit comments

Comments
 (0)