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

in membership test short-circuits evaluation for list literals #4465

Open
charles-cooper opened this issue Jan 23, 2025 · 1 comment
Open
Labels
needs triage needs triage

Comments

@charles-cooper
Copy link
Member

Version Information

  • vyper Version (output of vyper --version): v0.4.0

What's your issue about?

as an optimization, vyper currently expands array membership like x in [a, b, c] to x == a or x == b or x == c. however, this short circuits, which can lead to not evaluating side effects. for example,

def increment_counter() -> uint256:
    self.count += 1
    return self.count

def foo() -> uint256:
    if 1 in [self.increment_counter(), self.increment_counter()]:
        return self.counter  # returns 1
    return 0

How can it be fixed?

Fill this in if you know how to fix it.

@charles-cooper charles-cooper added the needs triage needs triage label Jan 23, 2025
@charles-cooper
Copy link
Member Author

charles-cooper commented Jan 23, 2025

this was reported by @montyly and @0xalpharush

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

No branches or pull requests

2 participants
@charles-cooper and others