Skip to content

compile: recursion check fails on non-recursive ref #8255

@anderseknert

Description

@anderseknert

This compiles:

package p

rule if {
    some root in ["foo", "bar"]
    data[root].sub
}

Whereas this doesn't:

package p

rule if {
    some root in ["foo", "bar"]
    data[root].rule
}

->

rego_recursion_error: rule data.p.rule is recursive: data.p.rule -> data.p.rule

Which we know is wrong since none of the values root resolves will produce the recursive data.p.rule ref that the error message claims. Without having looked at the code, I assume that root is considered dynamic, even though all possible values are known and could be checked at compile time. I don't think this check would need to cover all possible cases, but it should be able to identify at least simple cases like this where the variable part of a ref is just an enumeration of values known at compile time, and even local in scope. The use case is if course (not so dynamic) policy composition, where we want to run an input across a number of roots we know exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions