Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: iterator modification check has false positives and false negatives #3429

Closed
tserg opened this issue May 19, 2023 · 0 comments · Fixed by #3764
Closed

bug: iterator modification check has false positives and false negatives #3429

tserg opened this issue May 19, 2023 · 0 comments · Fixed by #3764

Comments

@tserg
Copy link
Collaborator

tserg commented May 19, 2023

Version Information

  • vyper Version (output of vyper --version): ed0a654
  • OS: linux
  • Python Version (output of python --version): 3.10.8

What's your issue about?

The _check_iterator_modification check in vyper/semantics/analysis/local.py has false positives and false negatives.

The first contract is a false negative, and the second contract is a false positive.

struct A:
    iter: DynArray[uint256, 5]

a: A

@external
def foo():
    self.a.iter = [1, 2, 3]
    for i in self.a.iter:
        self.a = A({iter: [1, 2, 3, 4]})
a: DynArray[uint256, 5]
b: uint256[10]

@external
def foo():
    self.a = [1, 2, 3]
    for i in self.a:
        self.b[self.a[1]] = i
Error compiling: tmp/iterator_false_positive.vy
vyper.exceptions.ImmutableViolation: Cannot modify array during iteration
  contract "tmp/iterator_false_positive.vy:8", function "foo", line 8:15 
       7     for i in self.a:
  ---> 8         self.b[self.a[1]] = i
  ----------------------^
       9

h/t @trocher @ptrcarta

How can it be fixed?

Fill this in if you know how to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant