Skip to content

Add *= and /= compound assignment sugar (and extended tests) - #537

Open
axic wants to merge 1 commit into
argotorg:mainfrom
axic:compound-statements
Open

Add *= and /= compound assignment sugar (and extended tests)#537
axic wants to merge 1 commit into
argotorg:mainfrom
axic:compound-statements

Conversation

@axic

@axic axic commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

The * / / operators (ExpTimes / ExpDivide, backed by the Mul / Div classes) already exist, but the matching compound assignments were missing while += -= ^= &= |= %= were all present. Add *= and /= so every binary arithmetic/bitwise operator has a compound assignment, desugaring lhs *= rhs to lhs := lhs * rhs (and likewise for /=), mirroring the existing %= sugar.

Guard the * and / infix operators against a following = (as % already is) so *= / /= are not mis-parsed as the operator followed by a failing operand.

  • AST: StmtTimesEq / StmtDivideEq, with name resolution, pretty printer and module type-ref renamer handling them.
  • Parser: *= / /= in both statement and for-clause assignment parsers; = guards on the * / / expression operators.
  • Tests: parser cases for x *= 2; / x /= 2;; a compound-operators.solc case test exercising the full += -= *= /= %= ^= &= |= set; and new basic dispatch entry points (mul2 / div2 and pluseq / minuseq / timeseq / divideeq / modeq / bxoreq / bandeq / boreq) giving the compound assignment statements end-to-end EVM coverage.

The `*` / `/` operators (ExpTimes / ExpDivide, backed by the Mul / Div
classes) already exist, but the matching compound assignments were
missing while `+= -= ^= &= |= %=` were all present. Add `*=` and `/=`
so every binary arithmetic/bitwise operator has a compound assignment,
desugaring `lhs *= rhs` to `lhs := lhs * rhs` (and likewise for `/=`),
mirroring the existing `%=` sugar.

Guard the `*` and `/` infix operators against a following `=` (as `%`
already is) so `*=` / `/=` are not mis-parsed as the operator followed
by a failing operand.

- AST: StmtTimesEq / StmtDivideEq, with name resolution, pretty printer
  and module type-ref renamer handling them.
- Parser: `*=` / `/=` in both statement and for-clause assignment
  parsers; `=` guards on the `*` / `/` expression operators.
- Tests: parser cases for `x *= 2;` / `x /= 2;`; a compound-operators.solc
  case test exercising the full `+= -= *= /= %= ^= &= |=` set; and new
  `basic` dispatch entry points (mul2 / div2 and pluseq / minuseq /
  timeseq / divideeq / modeq / bxoreq / bandeq / boreq) giving the
  compound assignment statements end-to-end EVM coverage.

Co-Authored-By: Alex Beregszaszi <alex@rtfs.hu>
@axic
axic force-pushed the compound-statements branch from 218bbc1 to 5445f89 Compare August 1, 2026 12:12
@axic axic mentioned this pull request Aug 1, 2026
23 tasks
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