opa icon indicating copy to clipboard operation
opa copied to clipboard

`every` isn't treated as a reserved keyword when `rego.v1` is imported

Open johanfylling opened this issue 1 year ago • 6 comments

The following module should produce a rego_parse_error: unexpected every keyword error:

package example
import rego.v1

every := "foo"

but it doesn't.

johanfylling avatar Mar 28 '24 09:03 johanfylling

if := "foo" also works, although less likely to be used as a var name. This is apparently valid:

package play

import rego.v1

if if "if"

😆

contains works too, but is special since there was a built-in function with that name already, which makes the keyword "context aware". Is that the case for if too?

anderseknert avatar Mar 28 '24 10:03 anderseknert

💭 Maybe in is the odd one, then?

srenatus avatar Mar 28 '24 10:03 srenatus

Another wrinkle: if you use every, you get an error:

package play

import rego.v1

p if {
	every x in [1, 2, 3] {
    	x < 4
    }
}

every := 42

->

1 error occurred: policy.rego:11: rego_parse_error: unexpected assign token
	every := 42
	      ^

It's not the expected unexpected keyword error, though.

We get the same error if we import future.keywords.every, so rego.v1 inherits that behavior.

johanfylling avatar Mar 28 '24 14:03 johanfylling

I don't really see the point in rejecting keywords that are part of a ref, though ..

package play

p if {
	input.import.x == 1
}

->

1 error occurred: policy.rego:4: rego_parse_error: unexpected import keyword: expected identifier
	input.import.x == 1
	      ^

Unless there is some reason not to that I'm missing, I'd like to loosen that constraint.

johanfylling avatar Mar 28 '24 14:03 johanfylling

Indeed

anderseknert avatar Mar 28 '24 15:03 anderseknert