mirror of
https://github.com/paradigmxyz/solidity-lean.git
synced 2026-11-15 19:56:39 +00:00
A block-local variable declaration that shadows a same-name state variable
(`uint256 sv=100; function run(){ { uint256 sv=5; sv+=1; } return sv; }`) was
lowered treating the shadowing local as the STATE variable: the source→core
identifier lowering keys a bare name on a fixed `storageNames` list that was only
narrowed for the function's own params/named returns, never for body-level
(including nested-block) locals. So `sv += 1` compiled to a storage
read-modify-write (100 -> 101) and `return sv` read storage, yielding
`success|w:101##STO##0:101` instead of solc+EVM's `success|w:100##STO##0:100`.
Fix: drop the shadowed names from `storageNames` at each statement/statement-list
lowering entry (`Stmt.lowerCore?` / `Stmt.listLowerCore?`), derived from the
already-threaded `env` via `TypeEnv.shadowedStateNames` — a name a nearer local
owns appears >=2x in `env` (each varDecl prepends its binding; state-var/param/
return/`this` names are otherwise unique). This is re-derived from the current
`env`, so it honours solc's nearest-declaration resolution and C99 block scoping:
the name reverts to the state variable once the local's block ends. Mirrors the
existing param-shadows-statevar exclusion (`stateNamesExcludingBound`).
Adds SolidCore.Witness.ShadowLocalNestedBlock.
Co-authored-by: Lean Semantics Review Agent <agent@solidcore.local>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
125 lines
4.5 KiB
125 lines
4.5 KiB