Skip to content
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

Unused output variable #60

Closed
anderseknert opened this issue Mar 27, 2023 · 1 comment · Fixed by #922
Closed

Unused output variable #60

anderseknert opened this issue Mar 27, 2023 · 1 comment · Fixed by #922

Comments

@anderseknert
Copy link
Member

foo {
	some x
	input[x]
}

Even in strict mode, OPA considers x to be "used", as it's referenced somewhere. Howver, unless x is referenced later in the rule (or in the rule head) it's not really used, and the above could be replaced by:

foo {
	input[_]
}

Or

foo {
	some _ in input
}
@anderseknert anderseknert changed the title Extended check for unused variables Unused output variable Aug 10, 2023
@anderseknert anderseknert moved this to TODO in Regal Oct 11, 2023
@anderseknert
Copy link
Member Author

Adding to this:

allow if {
	some i, x in input.message
}

Both i and x are unused here, but there's no warnings from neither OPA strict mode nor Regal.

@anderseknert anderseknert moved this from TODO to Planned in Regal Jun 4, 2024
anderseknert added a commit that referenced this issue Jul 17, 2024
One of the rules I've wanted since the project was started, but not until
now would this have been wildly expensive to add. With the recent fixes
that allow us to reuse the result of `walk`ing the AST, that's no longer
the case. Still, this required quite some time and effort to get right!

NOTE: this rule currently only considers output variables as found in
references, i.e. `x` in  `input[x]` and NOT `x` in `some x, _ in input`.
While that would be easy to add, I'm not sure if those are really "output
variables" or should be considered as such... 🤔 or if we should just have
another rules for "unused iteration variable" or something like that.
Either way, this is a big step forward!

Fixes #60

Signed-off-by: Anders Eknert <anders@styra.com>
@github-project-automation github-project-automation bot moved this from Planned to Done in Regal Jul 17, 2024
srenatus pushed a commit to srenatus/regal that referenced this issue Oct 1, 2024
One of the rules I've wanted since the project was started, but not until
now would this have been wildly expensive to add. With the recent fixes
that allow us to reuse the result of `walk`ing the AST, that's no longer
the case. Still, this required quite some time and effort to get right!

NOTE: this rule currently only considers output variables as found in
references, i.e. `x` in  `input[x]` and NOT `x` in `some x, _ in input`.
While that would be easy to add, I'm not sure if those are really "output
variables" or should be considered as such... 🤔 or if we should just have
another rules for "unused iteration variable" or something like that.
Either way, this is a big step forward!

Fixes StyraInc#60

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant