Skip to content

Fix Array.exists2 XML doc examples to use equal-length arrays#19672

Open
quyentho wants to merge 3 commits intodotnet:mainfrom
quyentho:fix-array-exists2-doc-examples
Open

Fix Array.exists2 XML doc examples to use equal-length arrays#19672
quyentho wants to merge 3 commits intodotnet:mainfrom
quyentho:fix-array-exists2-doc-examples

Conversation

@quyentho
Copy link
Copy Markdown

@quyentho quyentho commented May 3, 2026

Summary

The two Array.exists2 documentation examples in src/FSharp.Core/array.fsi used arrays of different lengths, which causes ArgumentException at runtime. Yet the docs claimed they evaluated to false and true respectively — making both examples incorrect.

  • Example 1: [| 1; 2 |] vs [| 1; 2; 0 |] (length 2 vs 3) — claimed false, actually throws
  • Example 2: [| 1; 4 |] vs [| 1; 3; 5 |] (length 2 vs 3) — claimed true, actually throws

Fix

Changed inputs2 in both examples to [| 1; 3 |] (length 2):

  • Example 1: [| 1; 2 |] vs [| 1; 3 |]false (1 > 1 = false, 2 > 3 = false ✓)
  • Example 2: [| 1; 4 |] vs [| 1; 3 |]true (1 > 1 = false, 4 > 3 = true ✓)

Test plan

  • Verify examples are runnable in F# interactive and produce the stated results
  • Confirm Array.exists2 (fun a b -> a > b) [| 1; 2 |] [| 1; 3 |] returns false
  • Confirm Array.exists2 (fun a b -> a > b) [| 1; 4 |] [| 1; 3 |] returns true

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)
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/FSharp.Core docs/release-notes/.FSharp.Core/11.0.100.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@quyentho
Copy link
Copy Markdown
Author

quyentho commented May 3, 2026

@dotnet-policy-service agree

@quyentho
Copy link
Copy Markdown
Author

quyentho commented May 3, 2026

Tracked in issue #19673.

Copy link
Copy Markdown
Member

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

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

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)

@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling May 4, 2026
@T-Gro T-Gro enabled auto-merge (squash) May 4, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants