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

Certain types of augmented assignments targets are evaluated twice #348

Closed
daniel-makerx opened this issue Nov 7, 2024 · 0 comments · Fixed by #352
Closed

Certain types of augmented assignments targets are evaluated twice #348

daniel-makerx opened this issue Nov 7, 2024 · 0 comments · Fixed by #352
Labels
bug Something isn't working

Comments

@daniel-makerx
Copy link
Contributor

daniel-makerx commented Nov 7, 2024

Subject of the issue

Augmented assignments that involve state or box storage can result in the sub-expressions of the left hand side being evaluated twice, for example the following code fails on the assert

from algopy import GlobalState, UInt64, arc4, subroutine


class AugmentedAssignmentIssue(arc4.ARC4Contract):

    def __init__(self) -> None:
        self.counter = UInt64()
        self.g = GlobalState(UInt64, key="g")
        self.g.value = UInt64()

    @arc4.abimethod()
    def test_augmented_assign(self) -> None:
        self.counter = UInt64()
        self.get_global_with_side_effect().value += 1
        assert self.counter == 1, "this errors, counter is 2!"

    @subroutine
    def get_global_with_side_effect(self) -> GlobalState[UInt64]:
        self.counter += 1
        return self.g

Expected behaviour

All expressions on the left hand side of augmented assignment is only evaluated once, i.e. in this example assert self.counter == 1 does not fail

@daniel-makerx daniel-makerx added the bug Something isn't working label Nov 7, 2024
@achidlow achidlow changed the title Augmented assignments are evaluated twice Certain types of augmented assignments targets are evaluated twice Nov 7, 2024
@daniel-makerx daniel-makerx linked a pull request Nov 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant