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
Potential bug: Non-property/method members are silently skipped.
Lines [114-116] specifically force a true return for the default case, meaning no diagnostic is ever raised for fields, events, or other non-overridable members. For example, if a user calls Setup(x => x.myField), the analyzer won't report a diagnostic. This appears to undermine the goal of restricting Setup to only overridable members.
Why it’s a bug: Fields and other non-method/non-property members are not overridable. The analyzer's stated objective is “Setup should be used only for overridable members.”
Example:
publicclassFoo{publicintmyField;}// In test:varmock=newMock<Foo>();mock.Setup(x =>x.myField).Returns(42);// Expect analyzer to warn, but it won't currently
Suggested fix: Return false in the default case, so the analyzer issues a diagnostic for members that aren’t recognized as a property or a method.
- default:- // If it's not a property or method, we do not issue a diagnostic- return true;+ default:+ // If it's not a property or method, it's not overridable+ return false;
Consider adding regression tests covering fields or events to ensure the analyzer flags them correctly going forward.
Potential bug: Non-property/method members are silently skipped.
Lines [114-116] specifically force a
true
return for the default case, meaning no diagnostic is ever raised for fields, events, or other non-overridable members. For example, if a user callsSetup(x => x.myField)
, the analyzer won't report a diagnostic. This appears to undermine the goal of restrictingSetup
to only overridable members.Why it’s a bug: Fields and other non-method/non-property members are not overridable. The analyzer's stated objective is “Setup should be used only for overridable members.”
Example:
Suggested fix: Return
false
in thedefault
case, so the analyzer issues a diagnostic for members that aren’t recognized as a property or a method.Consider adding regression tests covering fields or events to ensure the analyzer flags them correctly going forward.
Originally posted by @coderabbitai[bot] in #340 (comment)
The text was updated successfully, but these errors were encountered: