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
Detect return parameters that are just a receiving parameter #18
Comments
Hmm, the first type could be problematic with projects that use the idiom of chaining methods, like in |
I could imagine a situation where I define a method in anticipation of it changing later, say,
where later it might turn into (once a new field gets added):
The first way I'd have to go find every place Canceled was called and decide whether I really meant Suspended and change it. |
You're right, fields is also problematic. I think I'll just go for return parameters that are always one of the receiving parameters (minus method receivers). |
Also consider this case:
The return value is not necessary. |
@tehsphinx ah yes, modifying what's behind a pointer as long as the pointer itself is not modified means that the return value can still be unnecessary. Thanks for pointing that out. |
Implemented this, but starting to have some doubts that it's actually useful. On the latest tip, these are the newly found warnings:
None of them seem particularly good warnings. Thoughts? Perhaps run the tool on your codebases, grep for this new warning, and let me know if any of the warnings are actually useful. |
It was rarely useful, and it was particularly annoying with patterns where funcs would return the same parameters they got, which would make for simpler statements and expression when chaining these funcs or when using them as return arguments. See the discussion in #18. Shaves off 19 warnings off std cmd, which were mostly false positives like the above.
I have found the pattern of false positives. It's usually like:
I've analysed this check in other codebases as well as Disabling the check for now. If anyone wants to give it a test-run, they can always revert 18c5021 (or go to the commit right before it). |
In other words, when the values must already be in the hands of the caller.
For example, the receiver:
A receiver's field:
A received parameter:
Of course, the value must not have been modified under any of those cases.
The text was updated successfully, but these errors were encountered: