You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#pragma warning disable CS8524
enum MyEnum { A }
class C
{
void M()
{
bool? b = null;
_ = b switch // <= correctly warns about missing null arm with CS8655
{
true => 1,
false => 2,
};
MyEnum? x = null;
_ = x switch // <= does NOT warn about missing null arm with CS8655
{
MyEnum.A => "A",
};
}
}
Diagnostic Id: CS8655: The switch expression does not handle some null inputs (it is not exhaustive).
If this is a report about a bug in an analyzer, please include the diagnostic ID and message if possible (e.g. "IDE0030: Use coalesce expression").
Expected Behavior: nullable enum-variable switch-expression with missing null should yield CS8655
Actual Behavior: nullable enum-variable switch-expression with missing null does NOT yield CS8655
The text was updated successfully, but these errors were encountered:
juwens
changed the title
CS8655 (exhaustive enum) is not triggered for nullable num value
CS8655 (exhaustive enum) should be triggered for nullable enum values
Jan 20, 2025
@jcouv I don't think that's the issue here. The problem is that CS8655 is reported for bool? but not MyEnum?. CS8524 is reported for MyEnum? for the reason you describe. So perhaps the compiler does not report CS8655 anymore to avoid "repeating itself". But if customers suppress CS8524 (because they don't want to be warned about missing enum cases because they know they don't cast ints to enums), they won't get the CS8655 warning there...
@jcouv I don't think that's the issue here. The problem is that CS8655 is reported for bool? but not MyEnum?. CS8524 is reported for MyEnum? for the reason you describe. So perhaps the compiler does not report CS8655 anymore to avoid "repeating itself". But if customers suppress CS8524 (because they don't want to be warned about missing enum cases because they know they don't cast ints to enums), they won't get the CS8655 warning there...
correct. CS8524 isn't involved with the null-check at all. With CS8524 enabled, one should see 8655 and 8524, cause CS8524 only indicates "malicious" (MyEnum)42 values, but not a missing arm for null.
That the default _ => ... arm "fixes" both warnings is just a coincidence.
Version Used: C#12
Steps to Reproduce:
Diagnostic Id: CS8655: The switch expression does not handle some null inputs (it is not exhaustive).
If this is a report about a bug in an analyzer, please include the diagnostic ID and message if possible (e.g.
"IDE0030: Use coalesce expression"
).Expected Behavior: nullable enum-variable switch-expression with missing null should yield CS8655
Actual Behavior: nullable enum-variable switch-expression with missing null does NOT yield CS8655
The text was updated successfully, but these errors were encountered: