Repository navigation
Conversation
gnidan
force-pushed
the
bugc-array-push
branch
from
October 7, 2026 02:17
f6efc09 to
88d3d7a
Compare
Contributor
|
gnidan
force-pushed
the
bugc-fixed-array-layout
branch
from
October 7, 2026 02:27
9b8cfe6 to
c0ab7fa
Compare
gnidan
force-pushed
the
bugc-array-push
branch
from
October 7, 2026 02:28
88d3d7a to
a1a55f0
Compare
Member
Author
|
Included in #368. |
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.
Stacked on #364 (storage array layout), which this PR targets. Review that first.
BUG had no way to grow a dynamic array in storage. A write past the end was how such an array grew, but it left the length alone, so the array's pointer (which reads the length) showed nothing. This adds
push, as Solidity has it, and checks indexes against the length.Syntax.
a.push(v)writesvat indexa.length, then storesa.length + 1.a.push()adds a zero element: there is nopopordelete, so nothing can have written past the length.push()is what makes an array of arrays usable:m.push(); m[0].push(4);. BUG already parsesa.push(v)as a call whose callee is the member accessa.push, in the same place as.length, which is a member access. So no parser change was needed. The type checker used to reject any call whose callee was not an identifier. It now acceptspushon a dynamic array in storage (directly, or inside a mapping or a struct), with at most one argument assignable to the element type. A push has no value, like a call to a function with no return type.pushon a memory array or a fixed-size array is a type error.Bounds. An index into a dynamic array in storage now reverts with
Panic(0x32)unless it is less than the length in the array's slot, for reads and writes, as #344 does for memory. The push's own write at indexlengthskips the check. An array literal's writes skip it too, because they store the length first..lengthin storage.a.lengthon a dynamic array in storage did not read the array's slot. It went through the memorylengthinstruction on a value that is not a memory address, so the tests here read 0 at the top level and garbage for an inner array. It now reads the slot, through the same storage access chain as an element.The
nested-arrays.bugexample wrotematrix[2][5]into empty arrays. It now pushes rows and elements first. In the BUG case study, the paragraph that said a write past the end grows the array now describespush.Conflicts to expect: #355, #357 and #359 also change
irgen/generate/expressions/access.ts, and #361 changesirgen/generate/storage.ts.