Fix Array.exists2 XML doc examples to use equal-length arrays#19672
Open
quyentho wants to merge 3 commits intodotnet:mainfrom
Open
Fix Array.exists2 XML doc examples to use equal-length arrays#19672quyentho wants to merge 3 commits intodotnet:mainfrom
quyentho wants to merge 3 commits intodotnet:mainfrom
Conversation
Both examples used arrays of different lengths (2 vs 3 elements), which would cause ArgumentException at runtime. The documented 'Evaluates to false/true' results were therefore incorrect. Fixed by using equal-length input arrays that produce the stated results: - inputs2 = [| 1; 3 |] with inputs1 = [| 1; 2 |] evaluates to false (neither 1>1 nor 2>3) - inputs2 = [| 1; 3 |] with inputs1 = [| 1; 4 |] evaluates to true (4>3)
Contributor
❗ Release notes required
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
@dotnet-policy-service agree |
Author
|
Tracked in issue #19673. |
T-Gro
approved these changes
May 4, 2026
Member
T-Gro
left a comment
There was a problem hiding this comment.
Thanks, we definitely should not have examples that throw.
The preconditions are slightly more complicates - the collections can have different lengths, but only if the predicate holds while both still have elements to be processed.
(i.e. only if it evaluates to true)
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.
Summary
The two
Array.exists2documentation examples insrc/FSharp.Core/array.fsiused arrays of different lengths, which causesArgumentExceptionat runtime. Yet the docs claimed they evaluated tofalseandtruerespectively — making both examples incorrect.[| 1; 2 |]vs[| 1; 2; 0 |](length 2 vs 3) — claimedfalse, actually throws[| 1; 4 |]vs[| 1; 3; 5 |](length 2 vs 3) — claimedtrue, actually throwsFix
Changed
inputs2in both examples to[| 1; 3 |](length 2):[| 1; 2 |]vs[| 1; 3 |]→false(1 > 1 = false, 2 > 3 = false ✓)[| 1; 4 |]vs[| 1; 3 |]→true(1 > 1 = false, 4 > 3 = true ✓)Test plan
Array.exists2 (fun a b -> a > b) [| 1; 2 |] [| 1; 3 |]returnsfalseArray.exists2 (fun a b -> a > b) [| 1; 4 |] [| 1; 3 |]returnstrue