Skip to content

Unexpected behavior when rule name contains dash #7433

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
anderseknert opened this issue Mar 9, 2025 · 2 comments
Open

Unexpected behavior when rule name contains dash #7433

anderseknert opened this issue Mar 9, 2025 · 2 comments

Comments

@anderseknert
Copy link
Member

anderseknert commented Mar 9, 2025

Dashes are not allowed in (simple) rule names, and need to be quoted in refs. Users unaware of this will however not learn this from OPA, as this surprisingly parses and compiles:

package p

foo-bar := 1

It will not evaluate though (undefined). Compiling with strict mode on will result in an error, but not one you'd reasonably expect:

2 errors occurred:
policy.rego:3: rego_compile_error: unused argument foo. (hint: use _ (wildcard variable) instead)
policy.rego:3: rego_compile_error: unused argument bar. (hint: use _ (wildcard variable) instead)

Running opa fmt on this policy tells us what OPA seems to see here:

package p

minus(foo, bar) := 1

Which while it explains the observed behavior, doesn't explain why a dash (or a minus if you will) in between two words "expands" to minus with the symbols to the left and right as arguments.

Checking the AST confirms this representation as well, so this issue seems to be in the parser.

Desired behavior here would IMO be that this rendered an error explaining that the dash is not valid at that position.

@anderseknert
Copy link
Member Author

I should probably add that the dash/minus isn't special here — any operator (built-in function with an infix attribute) will behave the same way, i.e. p/q := 1, a+b := 2, etc. The dash is just most likely to be actually used here.

Copy link

stale bot commented Apr 10, 2025

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

@stale stale bot added the inactive label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant