test: indexed (compound) assignment evaluation order and single-evaluation#16756
Open
msooseth wants to merge 1 commit into
Open
test: indexed (compound) assignment evaluation order and single-evaluation#16756msooseth wants to merge 1 commit into
msooseth wants to merge 1 commit into
Conversation
Pin down evaluation order and single-evaluation in indexed
(compound) assignment:
- In `a[f()] = g()`, RHS `g()` is evaluated before the LHS index
`f()`, so RHS side effects are observable when the index is
computed.
- In `a[f()] += v`, the LHS index `f()` is evaluated exactly once;
the slot computation is not re-evaluated for the write side.
Complements viaYul/tuple_evaluation_order.sol.
35aab63 to
e11b7a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a semantic test pinning down two invariants for indexed assignment:
a[f()] = g(), the RHSg()is evaluated before the LHS indexf(), so RHS side effects are observable when the index is computed.a[f()] += v, the LHS indexf()is evaluated exactly once; the slot computation is not re-evaluated for the write side.Coverage gap
No existing semantic test exercises a side-effecting function call as the LHS index of a compound assignment. Closest neighbors and why they don't cover it:
viaYul/tuple_evaluation_order.sol— tuple-LHS order; not indexed, not compound.operators/compound_assign{,_transient_storage}.sol— compound assign on plain state vars; no side-effecting LHS.modifiers/evaluation_order.sol,operators/userDefined/operator_evaluation_order.sol,errors/require_error_evaluation_order_*.sol— evaluation order in modifiers / user-defined operators /requireargs; different mechanism.cleanup/cleanup_in_compound_assign.sol— truncation cleanup, not order or single-eval.variables/mapping_local_compound_assignment.sol— LHS-with-side-effect, but plain=.array/indexAccess/bytes_index_access.sol,libraries/internal_call_attached_with_parentheses.sol— indexed compound assign, but constant index and no side effects.Complements
viaYul/tuple_evaluation_order.sol.