[JS/TS] Fix ResizeArray index getter/setter not throwing IndexOutOfRangeException when index is out of bounds#4408
Merged
MangelMaxime merged 2 commits intomainfrom Mar 16, 2026
Conversation
Route ResizeArray.get_Item and ResizeArray.set_Item through Array.item and Array.setItem lib calls respectively, which perform bounds checking and throw IndexOutOfRangeException on out-of-bounds access - consistent with .NET behavior and the existing bounds checking for regular arrays. Fix #3812 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5362d51 to
b566c48
Compare
Member
|
I made the tests pass for this PR. In order to make TypeScript, works I needed to annotate I picked |
6 tasks
ResizeArray index getter/setter not throwing IndexOutOfRangeException when index is out of bounds
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Fixes #3812 — accessing or setting a
ResizeArrayitem by index out of bounds silently returnsundefined(or does nothing) instead of throwing anIndexOutOfRangeExceptionas .NET does.Root cause: In
Replacements.fs,ResizeArray.get_ItemandResizeArray.set_Itemwere routed throughgetExpr/setExpr, which produce direct JavaScript index access (array[idx]). This bypasses the bounds check that regular arrays get viaArray.itemandArray.setIteminfable-library.Fix: Route
ResizeArray.get_Itemandset_ItemthroughHelper.LibCalltoArray.itemandArray.setItemrespectively. These functions check thatindex >= 0 && index < array.Lengthand throwinvalidArg "index" "Index was outside the bounds of the array."otherwise — consistent with .NET behavior.Test: Added two test cases in
ResizeArrayTests.fscovering out-of-bounds get and set.Trade-offs: This change adds a bounds check on every ResizeArray index access, matching the semantics of arrays (which already had this behaviour after #3729/#3748). The performance impact is minimal and the correctness gain is significant.
Closes #3812