Skip to content

Commit

Permalink
Fixed issue with list add_assign with str
Browse files Browse the repository at this point in the history
  • Loading branch information
AryazE committed Aug 28, 2024
1 parent 652f747 commit f722cfc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/dynapyt/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,33 +226,36 @@ def _aug_assign_(self, dyn_ast, iid, left, opr, right):
"binary_operation", dyn_ast, iid, operator[opr][:-6], left, right, None
)
self.call_if_exists(snake(operator[opr][:-6]), dyn_ast, iid, left, right, None)
eval_left = left()
if opr == 0:
new_val = eval_left + right
elif opr == 1:
new_val = eval_left & right
elif opr == 2:
new_val = eval_left | right
elif opr == 3:
new_val = eval_left ^ right
elif opr == 4:
new_val = eval_left / right
elif opr == 5:
new_val = eval_left // right
elif opr == 6:
new_val = eval_left << right
elif opr == 7:
new_val = eval_left @ right
elif opr == 8:
new_val = eval_left % right
elif opr == 9:
new_val = eval_left * right
elif opr == 10:
new_val = eval_left**right
elif opr == 11:
new_val = eval_left >> right
elif opr == 12:
new_val = eval_left - right
try:
eval_left = left()
if opr == 0:
new_val = eval_left + right
elif opr == 1:
new_val = eval_left & right
elif opr == 2:
new_val = eval_left | right
elif opr == 3:
new_val = eval_left ^ right
elif opr == 4:
new_val = eval_left / right
elif opr == 5:
new_val = eval_left // right
elif opr == 6:
new_val = eval_left << right
elif opr == 7:
new_val = eval_left @ right
elif opr == 8:
new_val = eval_left % right
elif opr == 9:
new_val = eval_left * right
elif opr == 10:
new_val = eval_left**right
elif opr == 11:
new_val = eval_left >> right
elif opr == 12:
new_val = eval_left - right
except:
new_val = None
self.call_if_exists("memory_access", dyn_ast, iid, new_val)
self.call_if_exists("write", dyn_ast, iid, [left], new_val)
result_high = self.call_if_exists(
Expand Down
6 changes: 6 additions & 0 deletions tests/regression/add_assign_list_str/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from dynapyt.analyses.BaseAnalysis import BaseAnalysis


class TestAnalysis(BaseAnalysis):
def add_assign(self, dyn_ast, iid, left, right):
print(f"add assign: {left} += {right}")
1 change: 1 addition & 0 deletions tests/regression/add_assign_list_str/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add assign: <function <lambda> at <...>> += hello
2 changes: 2 additions & 0 deletions tests/regression/add_assign_list_str/program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = []
a += "hello"

0 comments on commit f722cfc

Please sign in to comment.