Skip to content

Fix Enumerable.Sequence for NaN arguments and a zero step - #633

Merged
SimonCropp merged 1 commit into
mainfrom
fix/sequence-nan-zero-step
Oct 11, 2026
Merged

SimonCropp merged 1 commit into
mainfrom
fix/sequence-nan-zero-step

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Bug

The Enumerable.Sequence polyfill (net7 to net9) diverged from the net10 BCL:

  • A NaN start, endInclusive or step was not rejected. Every comparison with NaN is false, so the result was an endless sequence. The BCL throws ArgumentOutOfRangeException at the call, naming the offending parameter.
  • A zero step was treated as a negative step, so Sequence(1, 5, 0) threw for endInclusive and Sequence(5, 1, 0) returned [5]. The BCL throws ArgumentOutOfRangeException for step unless start == endInclusive, in which case it yields the single value.
  • The existing range checks passed the message text as the paramName ("endInclusive < start"). The BCL uses endInclusive.

Fix

Mirror the BCL: reject NaN up front, branch on step > 0 / step < 0, and handle step == 0 (including -0.0) separately. Exceptions now carry the same ParamName as the BCL.

Test

New Sequence_* tests for a NaN start, end and step, a zero and negative-zero step, a zero step with start == endInclusive, and the ParamName of the existing range checks. None of them enumerate, since the checks are not deferred. Five of the six failed on net8.0 before the fix. They pass on net8.0 and net9.0 (polyfill) and net10.0 (BCL). The expected behaviour was confirmed against net10 first. The net7.0 runtime is not installed on this machine, so net7.0 was compiled but not run.

@SimonCropp SimonCropp added this to the 11.4.4 milestone Oct 11, 2026
@SimonCropp
SimonCropp merged commit d8834f6 into main Oct 11, 2026
5 checks passed
@SimonCropp
SimonCropp deleted the fix/sequence-nan-zero-step branch October 11, 2026 22:12
This was referenced Oct 12, 2026
This was referenced Oct 13, 2026
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