Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming: ir_lvalue_compound_assignment.sol -> compound_assignment_evaluation_order_and_single_eval.sol. It does n

Let's also put it in operators/. Or create a separate dir for evaluation order. This viaYul/ dir is a legacy thing and we should get rid of it, moving tests to more relevant locations, not add more. I'm not even sure why they were singled out in the first place (most of them don't seem particularly IR-specific). Now it just makes it harder to check if we have a test for something already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know. I have moved it now :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Pins down evaluation order and single-evaluation for indexed
// (compound) 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.
contract C {
uint[2] public a;
uint public counter;

function bumpIdx() internal returns (uint) {
counter += 1;
return counter - 1;
}

function calculateVal() internal returns (uint) {
return 10 * (counter + 100);
}

function run() public returns (uint c, uint a0, uint a1) {
a[bumpIdx()] = calculateVal();
a[bumpIdx()] = calculateVal();
c = counter;
a0 = a[0];
a1 = a[1];
}
}
// ----
// run() -> 2, 1000, 1010