Open TessenR opened 4 years ago
I believe this is by design. {}
is considered a "pure" null check. Therefore, using it implies that you expect that the input might be null, and we take that into consideration to consider the input possibly null. If you want to handle all inputs, use a wildcard instead (e.g. var _
or _
).
Version Used:
Steps to Reproduce:
Compile the following code:
Expected Behavior: No warnings. Suppressed expressions are considered not nullable in all other contexts so this switch's input should be considered not nullable
Actual Behavior:
warning CS8655: The switch expression does not handle some null inputs (it is not exhaustive).
is reportedNotes The current behavior makes it impossible to easily suppress the warning as the following doesn't work either:
(s switch { {} => 1 })!