Open johanfylling opened 1 year ago
Alternatively, it should be a parser error to declare a zero-arg rule.
I would suggest taking a stand here instead. The title of this issue suggests as much :)
IMO unless we think there is an actual need for user-defined zero-argument functions, this should be a parser error.
I would suggest taking a stand here instead. The title of this issue suggests as much :)
My intention was to bring this up for discussion. But in retrospect, I should have done that as a comment, and not as part of the description.
Yeah, no worries @johanfylling 🙂
@ashutosh-narkar seeing these used in policy libraries working on Regal integrations is what brought this up. Longer discussion on Slack, but since that's only retained for 90 days, motivation summarized for posterity. The arguments for allowing zero-arity functions:
opa.runtime()
, rego.metadata.rule()
, etc)Thanks for the context @anderseknert! This list looks reasonable.
Make sure to add #6314 as a testcase for when this gets implemented.
It's possible to declare functions with zero arguments in Rego:
these are however treated as regular rules, and there is no semantic difference between the above policy and:
This is cause for confusion, as the user likely expects
foo()
to behave as a function (e.g. not contribute to output document), but it will actually behave as a rule.Alternatively, it should be a parser error to declare a zero-arg rule.