Skip to content

Fix nullness narrowing in match inside comprehensions#19743

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

Fix nullness narrowing in match inside comprehensions#19743
T-Gro wants to merge 2 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

…#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>
@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
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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
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