I notice when using a switch expression which includes a null check as the range expression, the nullability state of the value in arms/cases isn't interpreted correctly in Visual Studio (16.7.6). For example:
string? value = GetSomeString();
var description = (value != null) switch
{
true when value.Length == 0 => "Empty",
true when value.Length == 1 => "Uno",
true when value.Length == 3 => "Third time's a charm",
_ => "null"
};
Here I expect to know within the switch block that all instances of value
are not null, given the condition we're switching on. The last/default case handles the null case. Yet, Visual Studio thinks the first instance might be null:
Am I doing something wrong, is this a bug with the analyzer, or otherwise?