Skip to content

Give a nested array literal's inner arrays heap storage of their own - #356

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-nested-const-array-push
Sep 24, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-nested-const-array-push

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

const nested = [[1, 2], [3]]; nested[1].push(4) crashed in GC_realloc, and nested[0][0] = 9 wrote into constant data.

The literal is a const_array<array<s32>>. Turning it into an array<array<s32>> copied only the outer data to the heap, and the inner arrays kept pointing at the literal's constant globals. castConstArrayToArray skipped the literal because the element types already matched.

It now rebuilds a literal whose elements are arrays element by element even when the types match, so each inner array is cast, and copied to the heap, in turn. Deeper nesting recurses. Found while testing #354.

Verification

  • New test 00nested_array_literal_mutation.ts (compile, jit, and the rc/none corpus). It covers const, let, three levels deep, a module-level literal, and a fresh literal per loop iteration. On main it crashes.
  • Windows Release: 2865/2865 passed.
  • Linux (WSL): 2859/2859 passed.

🤖 Generated with Claude Code

`const nested = [[1, 2], [3]]; nested[1].push(4)` crashed in the
allocator. The literal is a const_array<array<s32>>, and turning it into
an array<array<s32>> copied only the outer data to the heap: the inner
arrays kept pointing at the literal's constant data, so push reallocated
a global and `nested[0][0] = 9` wrote one.

castConstArrayToArray skipped the literal because the element types
already matched. It now rebuilds a literal whose elements are arrays
element by element even then, so each inner array is cast - and copied
to the heap - in turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 8002753 into main Sep 24, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-nested-const-array-push branch September 24, 2026 00:00
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.

1 participant