Nullness issue - Incorrect type inferred when pattern matching with primary branch inferred from a member call. #18015
Labels
Area-Nullness
Issues related to handling of Nullable Reference Types
Bug
Impact-Medium
(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone
Issue description
If in a pattern match, the first branch returns a non-nullable ref type, the overall expression is (correctly) inferred to be of that type. However, subsequent branches allow you to still return nulls.
Choose one or more from the following categories of impact
null
constructs in code not using the checknulls switch.null
,not null
).Operating System
Windows (Default)
What .NET runtime/SDK kind are you seeing the issue on
.NET SDK (.NET Core, .NET 5+)
.NET Runtime/SDK version
.NET 9
Reproducible code snippet and actual behavior
z
is (apparently) inferred to bestring
, yet thefalse
branch is permitted.Possible workarounds
Putting in an explicit annotation forces the compiler to give FS3261:
Related to #18012 perhaps.
The text was updated successfully, but these errors were encountered: