Skip to content

Fix repeated target evaluation in compound assignments - #45

Open
gabriel-andreescu wants to merge 1 commit into
Orvid:masterfrom
gabriel-andreescu:fix-compound-assignment-targets
Open

gabriel-andreescu wants to merge 1 commit into
Orvid:masterfrom
gabriel-andreescu:fix-compound-assignment-targets

Conversation

@gabriel-andreescu

Copy link
Copy Markdown

Compound assignments such as values[NextIndex()] += 1 call NextIndex() twice,
so the read and write can target different elements. Member assignments such as
NextObject().Value += 1 have the same problem.

Capture the array reference and index, or member receiver, once and reuse them
for the read and write. This also keeps the target stable if the right-hand
expression changes it.

Checked generated PEX for Skyrim and Fallout 4, including struct members and
all five compound operators.

Fixes #11.

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 this pull request may close these issues.

Unexpected behavior with certain op-equals operations on array elements

1 participant