Closed safern closed 3 years ago
Closing as this behavior is currently "By Design". The null forgiving operator today is only allowed in an expression context, not in a type context. Not opposed to this but we'd need to make this a language change proposal on dotnet/csharplang.
I think people should be allowed to bang this warning away on the generic type use
Gives a syntax error. So this forces me to either use a pragma warning disable, or make my class
Foo<T, TComparer>
to accept anIComparer<T>?
and then bang away the call to_comparer!.Compare(_value, other)
because I know_comparer
will not be null.Also, when I'm creating the instance of this class, the compiler can identify that
TComparer
is will not be null at the callsite because I'm doing a null check on it:Repro can be found here
So maybe the warning on
FooMethodIComparable(value, new Foo<T, TComparer>
should never be produced?cc: @dotnet/nullablefc @cston