Fix nullness flow for objnull
from failwith
after null pattern
#18852
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.
Problem
When nullness checking is enabled, variables in non-null branches of match expressions should be refined to non-null types, but type aliases were not being preserved during this refinement process.
Consider this example:
Previously, the type alias
objnull
would be stripped during nullness refinement, and the variablex
would lose its connection to the original type alias.Root Cause
The issue was in the
removeNull
function withinTcMatchClause
inCheckExpressions.fs
. The original implementation used:This approach stripped type abbreviations using
stripTyEqns
and then applied the nullness refinement to the stripped type, losing the original type alias information.Solution
Modified the nullness refinement logic to:
stripTyEqns
only for decision-making (to determine if refinement is applicable)KnownWithoutNull
nullness while preserving the original type constructor and type argumentsThe new implementation:
Impact
objnull = obj | null
are now preserved in non-null branchesfailwith ""
) and explicit type aliasesTesting
Added comprehensive test cases covering:
failwith ""
creates unconstrained typesobj | null
string | null
Fixes #18488
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.