Skip to content

New rule: var arguments should be initialized before the call #132

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

Open
3 tasks done
Chadehoc opened this issue Dec 11, 2023 · 1 comment
Open
3 tasks done

New rule: var arguments should be initialized before the call #132

Chadehoc opened this issue Dec 11, 2023 · 1 comment
Labels
feature New feature or request rule Improvements or additions to rules

Comments

@Chadehoc
Copy link

Prerequisites

  • This rule has not already been suggested.
  • This should be a new rule, not an improvement to an existing rule.
  • This rule would be generally useful, not specific to my code or setup.

Suggested rule title

VarArgumentsShouldBeInitialized

Rule description

In #127, there was a discussion on whether var argument should be considered as initializing a variable. Although out arguments should be preferred for that, a confusion in the Delphi compiler (out and var are processed similarly) has lead some teams to accept initialization through var. So, this was suggested as a new rule rather than an improvement or the rule that "variables should be initialized before being used".

This rule states that a variable is "used" when passed as a var argument to a function call, so doing so without the variable being initialized should be warned against.

Rationale

If you do not accept in your code base that initialization could be done via a var argument, then the rationale is the same as stating that a variable should be initialized before being used.

It is especially important for record variables, for which the Delphi compiler does not enforce this basic rule!

@Chadehoc Chadehoc added feature New feature or request rule Improvements or additions to rules triage This needs to be triaged by a maintainer labels Dec 11, 2023
@Cirras
Copy link
Collaborator

Cirras commented Dec 12, 2023

Thanks, this seems like a good companion rule to VariableInitialization.

For the rule title, I'm thinking: VarArgumentInitialization

@Cirras Cirras removed the triage This needs to be triaged by a maintainer label Dec 12, 2023
@Cirras Cirras changed the title VAR arguments should be initialized before the call New rule: var arguments should be initialized before the call Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request rule Improvements or additions to rules
Projects
None yet
Development

No branches or pull requests

2 participants