-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix function return value not used inspection #5338
Fix function return value not used inspection #5338
Conversation
Previously, it reported on declarations, which does not help in finding the offending call sites. An inspection with the old intended behaviour will be added again in the next commits.
This is basically what the old FunctionReturnValueNotUsedInspection was supposed to be.
Codecov Report
@@ Coverage Diff @@
## next #5338 +/- ##
=======================================
Coverage ? 61.33%
=======================================
Files ? 1146
Lines ? 38812
Branches ? 8236
=======================================
Hits ? 23803
Misses ? 13389
Partials ? 1620
|
In the original PR description, I forgot to mention that this PR also makes an adjustment to the It also introduces a base class for inspections investigating declarations of a given type. |
//protected override IEnumerable<IInspectionResult> DoGetInspectionResults() | ||
//{ | ||
// var interfaceMembers = State.DeclarationFinder.FindAllInterfaceMembers().ToList(); | ||
// var interfaceImplementationMembers = State.DeclarationFinder.FindAllInterfaceImplementingMembers(); | ||
// var functions = State.DeclarationFinder | ||
// .UserDeclarations(DeclarationType.Function) | ||
// .Where(item => item.References.Any(r => !IsReturnStatement(item, r) && !r.IsAssignment)) | ||
// .ToList(); | ||
// var interfaceMemberIssues = GetInterfaceMemberIssues(interfaceMembers); | ||
// var nonInterfaceFunctions = functions.Except(interfaceMembers.Union(interfaceImplementationMembers)); | ||
// var nonInterfaceIssues = GetNonInterfaceIssues(nonInterfaceFunctions); | ||
// return interfaceMemberIssues.Union(nonInterfaceIssues); | ||
//} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, forgot to remove that after testing that things still work. Will remove.
@@ -46,159 +44,54 @@ namespace Rubberduck.Inspections.Concrete | |||
/// End Function | |||
/// ]]> | |||
/// </example> | |||
public sealed class FunctionReturnValueNotUsedInspection : InspectionBase | |||
public sealed class FunctionReturnValueNotUsedInspection : IdentifierReferenceInspectionBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping in mind that renaming an inspection is a breaking change as far as user configurations go, should this one be renamed DiscardedFunctionReturnValue
since we're introducing FunctionReturnValueNeverUsed
? That would do away with the "NotUsed"/"NeverUsed" dichotomy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC we have that dichotomy in other inspection names as well (didn't check though). If that is the case, then we should either "fix" all of them or keep all of them the same (to keep breaking change occurences minimal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My problem with the old name is that it led to confusion more than once. It suggests that it is about the usage. However, the original inspection is about the declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had a look: we only use NotUsed, so far. However, in all other cases, it is not ambiguous. (Here, the problem is that the return value can mean the individual value.)
I will rename FunctionReturnValueNotUsedInspection
to FunctionReturnValueDiscardedInspection
.
Should I rename FunctionReturnValueNeverUsedInspection
to FunctionReturnValueAlwaysDiscardedInspection
, as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I like how "AlwaysDiscarded" avoids "Not"/"Never" wording. Might as well!
@@ -217,7 +217,7 @@ If the parameter can be null, ignore this inspection result; passing a null valu | |||
<data name="SelfAssignedDeclarationInspection" xml:space="preserve"> | |||
<value>An auto-instantiated object variable declaration at procedure scope changes how nulling the reference works, which can lead to unexpected behavior.</value> | |||
</data> | |||
<data name="FunctionReturnValueNotUsedInspection" xml:space="preserve"> | |||
<data name="FunctionReturnValueNeverUsedInspection" xml:space="preserve"> | |||
<value>A member is written as a function, but used as a procedure. Unless the function is recursive, consider converting the 'Function' into a 'Sub'. If the function is recursive, none of its external callers are using the returned value.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC the updated code handles recursive functions - the InspectionInfo
text should be amended accordingly, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inspection still does not report recursive functions; well, at least if the use their own return value. (The corresponding test still passes.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, reading that again, it suggests that recursive functions are reported. However, the tests test that it is not the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change the description or actually implement the behaviour mentioned in the description, including appropriate tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah the inspection should just do what it needs to do, the description likely mentions recursiveness because inspection info strings sometimes mention shortcomings of inspections' implementations - if the shortcoming is fixed, the mention of it serves no purpose anymore. Let's reword the description.
# Conflicts: # Rubberduck.Resources/Inspections/InspectionInfo.resx # Rubberduck.Resources/Inspections/InspectionNames.resx # Rubberduck.Resources/Inspections/InspectionResults.resx
Also includes some German translations.
This PR makes the
FunctionReturnValueNotUsedInspection
return the references where the function return value is discarded. It also reimplements the original inspection, now calledFunctionReturnValueNeverUsedInspection
, fixing the bugs I mentioned in issue #5337.AddressOf expressions are now considered uses of the return value since the obtained pointer will typically be passed to a Win API function implemented outside of VBA. This function will probably use the return value when it calls the function via the pointer and it typically depends on the return type being correct.