Skip to content

Fix nullness narrowing in match inside comprehensions#19743

Open
T-Gro wants to merge 3 commits into
mainfrom
fix/nullness-match-infer
Open

Fix nullness narrowing in match inside comprehensions#19743
T-Gro wants to merge 3 commits into
mainfrom
fix/nullness-match-infer

Conversation

@T-Gro
Copy link
Copy Markdown
Member

@T-Gro T-Gro commented May 15, 2026

Fix false-positive FS3261 when pattern matching narrows nullness inside seq/list/array comprehensions.

Fixes #19644

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

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

@T-Gro T-Gro requested a review from abonie May 15, 2026 12:26
@T-Gro T-Gro added AI-Auto-Resolve-Conflicts Opt-in: LabelOps merges main into this PR and resolves conflicts every 3h AI-Auto-Resolve-CI Opt-in: LabelOps triages CI failures on this PR every 3h labels May 15, 2026
@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label May 15, 2026
@github-actions github-actions Bot mentioned this pull request May 16, 2026
Copy link
Copy Markdown
Member Author

@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.

Clean fix. The refactoring of EliminateNullnessFromInputType into a standalone function is faithful (logic is unchanged) and threading the narrowed inputTy through the List.mapFold accumulator in CheckSequenceExpressions.fs mirrors exactly how TcMatchClauses already works for normal match expressions.

Verified:

  • The extracted function is logic-identical to the original inline code in TcMatchClause
  • condR from TcMatchPattern is Expr option, matching the function's whenExprOpt parameter
  • The shadowed inputTy in the fold correctly feeds the narrowed type into subsequent clauses' TcMatchPattern calls
  • TryWith in sequence expressions matches on g.exn_ty and doesn't need similar treatment
  • Tests cover all three comprehension flavors plus the no-for variant
  • Release notes present

LGTM.

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label May 18, 2026
T-Gro and others added 2 commits May 19, 2026 12:00
…#19644)

Extract null-narrowing helper EliminateNullnessFromInputType from
TcMatchClause and reuse it in TcSequenceExpression's SynExpr.Match
handler so the input type is narrowed across clauses inside
comprehensions, matching the behavior of plain match expressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro T-Gro force-pushed the fix/nullness-match-infer branch from b4abb73 to 3c45d20 Compare May 19, 2026 10:17
…ndency

The ImmutableHashSet<int>.Builder type is not available in the net472 test
compilation environment. Replace with string | null which tests the same
nullness narrowing logic without requiring external assembly references.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-Auto-Resolve-CI Opt-in: LabelOps triages CI failures on this PR every 3h AI-Auto-Resolve-Conflicts Opt-in: LabelOps merges main into this PR and resolves conflicts every 3h AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Nullness issue - Apparently incorrect 3261 in match arm

1 participant