Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix :: Nullness :: Allow nullable return type for first branches of match and ifthenelse expressions #18322

Conversation

T-Gro
Copy link
Member

@T-Gro T-Gro commented Feb 17, 2025

Addresses #18015 .
Addresses #18012 .

Before - the two samples with a question mark are a usability error by forcing the user into explicit annotation of the return type.
image

After:
See tests.

The first branch of an if or match expression can dictate the nullness of the resulting type.
This works both by returning "null" literal as well as by returning a maybe-null value.

The overall expression is then treated as returning T|null.

If the first branch returns a without null result, any appearance of a nullable type in further branches still leads to a nullness warning.

Copy link
Contributor

github-actions bot commented Feb 17, 2025

❗ 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/9.0.300.md

@T-Gro T-Gro marked this pull request as ready for review February 17, 2025 17:15
@T-Gro T-Gro requested a review from a team as a code owner February 17, 2025 17:15
@T-Gro T-Gro changed the title 18015 nullness issue incorrect type inferred when pattern matching with primary branch inferred from a member call Bugfix :: Nullness :: Allow nullable return type for first branches of match and ifthenelse expressions Feb 17, 2025
@T-Gro T-Gro enabled auto-merge (squash) February 21, 2025 09:50
…ed-when-pattern-matching-with-primary-branch-inferred-from-a-member-call
@T-Gro T-Gro merged commit f939050 into main Feb 21, 2025
33 checks passed
@T-Gro T-Gro deleted the 18015-nullness-issue---incorrect-type-inferred-when-pattern-matching-with-primary-branch-inferred-from-a-member-call branch February 24, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
3 participants