Skip to content

[JS/TS] Fix ResizeArray index getter/setter not throwing IndexOutOfRangeException when index is out of bounds#4408

Merged
MangelMaxime merged 2 commits intomainfrom
repo-assist/fix-issue-3812-resizearray-bounds-check-5eff9738b79ca803
Mar 16, 2026
Merged

[JS/TS] Fix ResizeArray index getter/setter not throwing IndexOutOfRangeException when index is out of bounds#4408
MangelMaxime merged 2 commits intomainfrom
repo-assist/fix-issue-3812-resizearray-bounds-check-5eff9738b79ca803

Conversation

@github-actions
Copy link
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Fixes #3812 — accessing or setting a ResizeArray item by index out of bounds silently returns undefined (or does nothing) instead of throwing an IndexOutOfRangeException as .NET does.

Root cause: In Replacements.fs, ResizeArray.get_Item and ResizeArray.set_Item were routed through getExpr/setExpr, which produce direct JavaScript index access (array[idx]). This bypasses the bounds check that regular arrays get via Array.item and Array.setItem in fable-library.

Fix: Route ResizeArray.get_Item and set_Item through Helper.LibCall to Array.item and Array.setItem respectively. These functions check that index >= 0 && index < array.Length and throw invalidArg "index" "Index was outside the bounds of the array." otherwise — consistent with .NET behavior.

Test: Added two test cases in ResizeArrayTests.fs covering 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

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

@github-actions github-actions bot added automation Automated changes repo-assist Created by Repo Assist labels Mar 15, 2026
@MangelMaxime MangelMaxime marked this pull request as ready for review March 15, 2026 15:50
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>
@MangelMaxime MangelMaxime force-pushed the repo-assist/fix-issue-3812-resizearray-bounds-check-5eff9738b79ca803 branch from 5362d51 to b566c48 Compare March 15, 2026 17:15
@MangelMaxime MangelMaxime requested a review from ncave March 15, 2026 17:17
@MangelMaxime
Copy link
Member

@ncave

I made the tests pass for this PR.

In order to make TypeScript, works I needed to annotate IList to a concrete type otherwise when annotated to : any then equal<float64>(0, item(0, ys) + item(2, ys)); would not works because item type could not be resolved correctly by TypeScript compiler.

I picked MutableArray for IList as it seems the more close/compatible type with it.

@MangelMaxime MangelMaxime changed the title [Repo Assist] [JS/TS] Fix ResizeArray index access not throwing IndexOutOfRangeException [JS/TS] Fix ResizeArray index getter/setter not throwing IndexOutOfRangeException when index is out of bounds Mar 16, 2026
@MangelMaxime MangelMaxime merged commit af59c6b into main Mar 16, 2026
23 checks passed
@MangelMaxime MangelMaxime deleted the repo-assist/fix-issue-3812-resizearray-bounds-check-5eff9738b79ca803 branch March 16, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Automated changes repo-assist Created by Repo Assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessing a ResizeArray out of bounds, should generate an exception, like on .NET

1 participant