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
Product and Version Used: Roslynator.Analyzers 4.12.6
Steps to Reproduce:
Similarly to the issue reported in #640 for casting this to an interface type it implements, this also happens f.e. when casting a (already null-checked) property to one of its interface types (shown using default interface implementation as that's where I noticed):
publicinterfaceI{voidM(){}}publicclassP:I;
public class C
{publicrequiredPProp{get;set;}publicvoidM(){if(this.Propis not null){(this.PropasI).M();// <--- RCS1202((I)this.Prop).M();}}}
Actual Behavior: warning RCS1202: Avoid NullReferenceException (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1202)
Expected Behavior:
No warning. Fixing the diagnostic by adding a null check like (this.Prop as I)?.M(); removes the warning, but then SonarAnalyzer.CSharp produces a warning instead as the property has already been checked for null and the as expression isn't considered to possibly be null here: warning S2589: Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589), which I believe to be correct?
The text was updated successfully, but these errors were encountered:
Product and Version Used: Roslynator.Analyzers 4.12.6
Steps to Reproduce:
Similarly to the issue reported in #640 for casting
this
to an interface type it implements, this also happens f.e. when casting a (already null-checked) property to one of its interface types (shown using default interface implementation as that's where I noticed):Actual Behavior:
warning RCS1202: Avoid NullReferenceException (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1202)
Expected Behavior:
No warning. Fixing the diagnostic by adding a null check like
(this.Prop as I)?.M();
removes the warning, but then SonarAnalyzer.CSharp produces a warning instead as the property has already been checked for null and theas
expression isn't considered to possibly be null here:warning S2589: Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589)
, which I believe to be correct?The text was updated successfully, but these errors were encountered: