fix: type checker accepts out-of-range numeric indices on arrays (#77)#98
Merged
fix: type checker accepts out-of-range numeric indices on arrays (#77)#98
Conversation
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.
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.
ECMA-262 array indices are integers in [0, 2^32 - 2]. Numeric literals outside that range — e.g.
a[4294967295]ora[-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 likebuilt-ins/Array/15.4.5.1-5-2.jsfrom ever reaching the runtime.Gate the element-type throw on a new
IsArrayIndexInRangehelper 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.jsTypeCheckError → 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.