The following code causes S2955. However comparing to default(T) instead of null as the rule suggests gives a compiler error. Even if it did compile, if T was int then default(T) would be zero which gives different behavior than comparing T? to null.
Repro steps
public bool Foo<T>(Func<T?> bar) where T : notnull
{
T? t = bar();
return t == null;
}
Description
The following code causes S2955. However comparing to default(T) instead of null as the rule suggests gives a compiler error. Even if it did compile, if T was int then default(T) would be zero which gives different behavior than comparing T? to null.
Repro steps
Expected behavior
Rule does not fire
Actual behavior
Rule does fire
Known workarounds
Ignore the rule
Related information