-
Notifications
You must be signed in to change notification settings - Fork 13
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
New rule: out
arguments should not be assigned before the call
#133
Comments
Makes sense to me - thanks! For the rule title, I'm thinking: |
out
arguments should not be assigned before the call
This is not true - when the type of the |
I think it's what #134 is for (ensure that the parameter is not read), and that missing It means #134 should be finished before this new rule is created.
Interesting point. I don't know what the policy is for a rule that should imply another one. I would argue that if an In this particular case, the only way the unappropriate correction would not be detected by sonar-delphi would be because an essential rule has been explicitely disabled (detecting uninitialized variables or unassigned results), provided #134 is done. |
Prerequisites
Suggested rule title
OutArgumentShouldNotBeCalledInitialized
Rule description
The discussion at the end of #127 leads me to propose this as a separate rule; but I would prefer it as a part of the rule proposed in #132, because it also has to do with the possible confusion between
var
andout
arguments (an integrated rule could be calledOutAndVarArgumentConfusion
).The Delphi compiler does not actually make a difference between
out
andvar
. This is confusing, and can lead to acceptingvar
as initializing the variable passed to it (rule #132 proposed against this). Another confusion is passing an initialized variable asout
argument, which means that the argument should actually bevar
. This rule aims to detect that case.Should be warned against:
An exception is when the variable is actually used before the call. Then it is just a reuse of an existing variable.
Rationale
Track the confusion between
out
andvar
arguments. While there is no difference for the compiler, there is a huge difference in intent and readability.The text was updated successfully, but these errors were encountered: