Skip to content

test: indexed (compound) assignment evaluation order and single-evaluation#16756

Open
msooseth wants to merge 1 commit into
argotorg:developfrom
msooseth:test-compound-assignment-lhs-side-effect
Open

test: indexed (compound) assignment evaluation order and single-evaluation#16756
msooseth wants to merge 1 commit into
argotorg:developfrom
msooseth:test-compound-assignment-lhs-side-effect

Conversation

@msooseth
Copy link
Copy Markdown
Contributor

@msooseth msooseth commented May 21, 2026

Adds a semantic test pinning down two invariants for indexed assignment:

  • In a[f()] = g(), the 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.

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 / require args; 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.

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.
@msooseth msooseth force-pushed the test-compound-assignment-lhs-side-effect branch from 35aab63 to e11b7a4 Compare May 21, 2026 11:44
@msooseth msooseth changed the title test: compound assignment LHS index single-evaluation test: indexed (compound) assignment evaluation order and single-evaluation May 21, 2026
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.

2 participants