Skip to content

Unexpected behavior when rule name contains dash #7433

@anderseknert

Description

@anderseknert

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions