Repository navigation
fix(all): read more for loop bounds once like .NET - #5287
Merged
Merged
Conversation
Contributor
Python Type Checking Results (Pyright)
Excluded files with errors (4 files)These files have known type errors and are excluded from CI. Remove from
|
MangelMaxime
force-pushed
the
fix/for-loop-bound-follow-up
branch
from
November 19, 2026 17:11
49d1256 to
a1ec839
Compare
for loop bounds once like .NET
MangelMaxime
marked this pull request as ready for review
November 19, 2026 20:37
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.
Part of #5285. Follow-up to #5282, which fixed the JS/TS loop bound for most shapes.
This PR fixes the shapes that #5282 could not fix in
Fable2Babel, and it applies the same rule to Dart and Beam.0 to Array.length a - 1on a mutable array reassigned in the body0 .. 1 .. a.Length - 1on a mutable array reassigned in the bodyfor x in awithareassigned in the body0 .. xs.Count - 1withxs.RemoveAt 0in the bodylet x = f 1 in x + f 1over 3 iterations, calls tof.NET reads
0 to a.Length - 1on a mutable array again on each iteration. JS/TS, Dart and Beam keep this behavior.Changes:
FSharp2Fablesees the F# calls, so it can tellArray.length afroma.Length. ForArray.length a - 1and for a step of 1, it binds the bound with aletbefore the loop.for x in aon a mutable array bindsawith aletbefore the loop.isStableForLoopLimit,isReReadForLoopLimitand the newmakeForLoopWithBoundLimitmove fromFable2Babel.fstoTransforms.Util.fs. Dart and Beam use them.Not fixed:
0 to a.Length - 1on a mutable array only once. .NET reads it again on each iteration.NameErroron Python,E0586on Rust).