Bugfix :: Nullness :: Allow nullable return type for first branches of match and ifthenelse expressions #18322
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.
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.

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.