Skip to content

fix: type checker accepts out-of-range numeric indices on arrays (#77)#98

Merged
nickna merged 1 commit intomainfrom
worktree-issue-77-uint32-array-index
May 1, 2026
Merged

fix: type checker accepts out-of-range numeric indices on arrays (#77)#98
nickna merged 1 commit intomainfrom
worktree-issue-77-uint32-array-index

Conversation

@nickna
Copy link
Copy Markdown
Owner

@nickna nickna commented May 1, 2026

ECMA-262 array indices are integers in [0, 2^32 - 2]. Numeric literals outside that range — e.g. a[4294967295] or a[-1] — are spec-equivalent to ordinary string-keyed property assignments and do not write into an array element slot. The element-type compatibility check in CheckSetIndex / CheckSetIndexOnType incorrectly fired for these, blocking Test262 cases like built-ins/Array/15.4.5.1-5-2.js from ever reaching the runtime.

Gate the element-type throw on a new IsArrayIndexInRange helper that returns false for numeric literals (including unary-minus literals) outside the valid array-index range. Non-literal indices keep the strict check — TypeScript-default behavior is preserved for typical code.

Test262 baseline movement: built-ins/Array/15.4.5.1-5-2.js TypeCheckError → RuntimeError in both interpreted and compiled buckets, matching the issue's stated acceptance ("some to RuntimeError where a distinct bug is exposed"). The remaining RangeError on assignment to index 2^32-1 is a runtime-side concern (next-layer sparse array work), not in scope for this issue.

ECMA-262 array indices are integers in [0, 2^32 - 2]. Numeric literals
outside that range — e.g. `a[4294967295]` or `a[-1]` — are spec-equivalent
to ordinary string-keyed property assignments and do not write into an
array element slot. The element-type compatibility check in CheckSetIndex
/ CheckSetIndexOnType incorrectly fired for these, blocking Test262 cases
like `built-ins/Array/15.4.5.1-5-2.js` from ever reaching the runtime.

Gate the element-type throw on a new `IsArrayIndexInRange` helper that
returns false for numeric literals (including unary-minus literals) outside
the valid array-index range. Non-literal indices keep the strict check —
TypeScript-default behavior is preserved for typical code.

Test262 baseline movement: `built-ins/Array/15.4.5.1-5-2.js`
TypeCheckError → RuntimeError in both interpreted and compiled buckets,
matching the issue's stated acceptance ("some to RuntimeError where a
distinct bug is exposed"). The remaining RangeError on assignment to
index 2^32-1 is a runtime-side concern (next-layer sparse array work),
not in scope for this issue.
@nickna nickna merged commit 86cb1e8 into main May 1, 2026
2 of 3 checks passed
@nickna nickna deleted the worktree-issue-77-uint32-array-index branch May 1, 2026 22:42
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