Skip to content

Commit

Permalink
catch extcall in for loop iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Oct 11, 2024
1 parent 4dfd983 commit cfd17fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/functional/syntax/test_for_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,21 @@ def bar(t: address):
None,
"extcall I(t).bar()",
),
(
"""
interface I:
def bar() -> DynArray[uint256, 10]: nonpayable
@external
def bar(t: address):
for i: uint256 in extcall I(t).bar():
pass
""",
StateAccessViolation,
"May not call state modifying function for loop iterator.",
None,
"extcall I(t).bar()",
),
]

for_code_regex = re.compile(r"for .+ in (.*):", re.DOTALL)
Expand Down
4 changes: 4 additions & 0 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ def _analyse_range_iter(self, iter_node, target_type):
def _analyse_list_iter(self, iter_node, target_type):
# iteration over a variable or literal list
iter_val = iter_node.reduced()
if isinstance(iter_val, vy_ast.ExtCall):
raise StateAccessViolation(
"May not call state modifying function for loop iterator.", iter_val
)

if isinstance(iter_val, vy_ast.List):
len_ = len(iter_val.elements)
Expand Down

0 comments on commit cfd17fe

Please sign in to comment.