open-policy-agent / opa

Open Policy Agent (OPA) is an open source, general-purpose policy engine.
https://www.openpolicyagent.org
Apache License 2.0
9.32k stars 1.29k forks source link

Hard to understand type error when referencing function as anything but function #6840

Open anderseknert opened 4 days ago

anderseknert commented 4 days ago

I had this happen to me today, and while it was pretty easy to spot my mistake, the only useful information from the error message was the location. Simplified example:

package play

import rego.v1

f(x) := x

allow if {
    some x in f
}
1 error occurred: policy.rego:8: rego_type_error: undefined ref: data.play.f[__local1__]
    data.play.f[__local1__]
    ^^^^^^^^^^^
    have: (any) => any

Something like function f used as reference, not called (or whatever) would be a better way to explain the actual issue here.