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
A null suppression throws the null warning suppression out of whack.
One might say why is str not getting checked for null. The following is a minimal repro, the actual scenarios I've ran into are less trivial. Suffice it to say, the existence of the null-suppression operator should be evidence enough that it needs to be used sometimes.
internalstaticstringGetString(HasStringstr){
Assert.That(str.Inner, Is.Not.Null);return str.Inner;// works great}internalstaticstringGetStringSuppress(HasString?str)// argument is nullable{
Assert.That(str!.Inner, Is.Not.Null);return str.Inner;// warning: possible null reference return}publicrecordHasString(string?Inner);
The text was updated successfully, but these errors were encountered:
In this case Assert.That(str?.Inner, Is.Not.Null); would have been a safer statement as it asserts both str and str.Inner.
But as you said, your real code is more complicated.
The null-suppression-operator indicates that the writer knows more about the code than the compiler can deduct.
I created a PR to ignore '!' when matching diagnostics with expressions tested with Is.Not.Null
A null suppression throws the null warning suppression out of whack.
One might say why is
str
not getting checked for null. The following is a minimal repro, the actual scenarios I've ran into are less trivial. Suffice it to say, the existence of the null-suppression operator should be evidence enough that it needs to be used sometimes.The text was updated successfully, but these errors were encountered: