Open TessenR opened 3 years ago
Very broadly, a switch on a tuple literal currently loses the nullability states of the tuple elements.
#nullable enable
public class C
{
public void M(string? x)
{
_ = ((x == null), 1) switch
{
(false, _) => x.ToString(), // warning CS8602: Dereference of a possibly null reference. (incorrect)
_ => throw null!
};
}
}
Version Used:
Steps to Reproduce:
Compile the following code
Expected Behavior: Warnings for
e.F
dereference in both methodsActual Behavior: Warning in
M2
but notM1
Notes Roslyn updates pure null check pattern operands to nullable in
NullableWalker.LearnFromAnyNullPatterns
but it ignores pattern matching over tuple expressions