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

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

Open
johanfylling opened this issue Mar 28, 2024 · 5 comments
Open

Comments

@johanfylling
Copy link
Contributor

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 johanfylling added this to Backlog in Open Policy Agent via automation Mar 28, 2024
@johanfylling johanfylling moved this from Backlog to Planning - v0.64 in Open Policy Agent Mar 28, 2024
@anderseknert
Copy link
Member

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?

@srenatus
Copy link
Contributor

💭 Maybe in is the odd one, then?

@johanfylling
Copy link
Contributor Author

johanfylling commented Mar 28, 2024

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
Copy link
Contributor Author

johanfylling commented Mar 28, 2024

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.

@anderseknert
Copy link
Member

Indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Open Policy Agent
  
Planning - v0.64
Development

No branches or pull requests

3 participants