Skip to content

Commit

Permalink
add tests for repros from issue
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Feb 9, 2024
1 parent 69cec3e commit 135fc4e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/unit/semantics/analysis/test_for_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,45 @@ def baz():
validate_semantics(vyper_module, dummy_input_bundle)


def test_modify_iterator_through_struct(dummy_input_bundle):
# GH issue 3429
code = """
struct A:
iter: DynArray[uint256, 5]
a: A
@external
def foo():
self.a.iter = [1, 2, 3]
for i: uint256 in self.a.iter:
self.a = A({iter: [1, 2, 3, 4]})
"""
vyper_module = parse_to_ast(code)
with pytest.raises(ImmutableViolation) as e:
validate_semantics(vyper_module, dummy_input_bundle)

assert e.value._message == "Cannot modify loop variable `a`"


def test_modify_iterator_complex_expr(dummy_input_bundle):
# GH issue 3429
# avoid false positive!
code = """
a: DynArray[uint256, 5]
b: uint256[10]
@external
def foo():
self.a = [1, 2, 3]
for i: uint256 in self.a:
self.b[self.a[1]] = i
"""

vyper_module = parse_to_ast(code)
validate_semantics(vyper_module, dummy_input_bundle)


iterator_inference_codes = [
"""
@external
Expand Down

0 comments on commit 135fc4e

Please sign in to comment.