Skip to content

Conversation

@stephentoub
Copy link
Member

  • Use T.IsPositive/IsZero
  • Put zero check first
  • Throw for NaN
  • Rename a parameter to clarify its purpose
  • Add some comments

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the Sequence and AsyncSequence APIs to validate NaN, handle a zero step specially, renames a test method, and fleshes out the ReferenceAddable stub with the new INumber<T> members.

  • Add T.IsNaN checks before range and step logic
  • Introduce explicit handling when step == 0 to either repeat once or throw
  • Rename tests to InvalidArguments_Throws and implement new INumber members in ReferenceAddable

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Linq/tests/SequenceTests.cs Renamed test and added NaN-argument assertions
src/libraries/System.Linq/src/System/Linq/Sequence.cs Added NaN and zero-step checks and refactored iterator locals
src/libraries/System.Linq.AsyncEnumerable/tests/SequenceTests.cs Renamed test and added NaN-argument assertions
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/Sequence.cs Added NaN and zero-step checks and refactored iterator locals
Comments suppressed due to low confidence (2)

src/libraries/System.Linq/tests/SequenceTests.cs:23

  • Add tests for the zero-step behavior: when step == T.Zero and start == endInclusive, the sequence should yield exactly one element, and when start != endInclusive, it should throw ArgumentOutOfRangeException.
            AssertExtensions.Throws<ArgumentOutOfRangeException>("step", () => Enumerable.Sequence(1.0f, 1.0f, float.NaN));

src/libraries/System.Linq.AsyncEnumerable/tests/SequenceTests.cs:24

  • Similarly, add async tests covering the step == T.Zero cases: one element when start == endInclusive and throwing when start != endInclusive.
            AssertExtensions.Throws<ArgumentOutOfRangeException>("step", () => AsyncEnumerable.Sequence(1.0f, 1.0f, float.NaN));

- Use T.IsPositive/IsZero
- Put zero check first
- Throw for NaN
- Rename a parameter to clarify its purpose
- Add some comments
@stephentoub
Copy link
Member Author

/ba-g infra failures

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants