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

Type checker fails to identify type from reference #7273

Open
anderseknert opened this issue Jan 16, 2025 · 2 comments
Open

Type checker fails to identify type from reference #7273

anderseknert opened this issue Jan 16, 2025 · 2 comments
Labels

Comments

@anderseknert
Copy link
Member

No error reported

package p

a := "foo"
s := sum([1, a])

This should fail as sum only accepts numeric values. However, it doesn't. When the value is used directly, the type checker correctly reports the error.

Error reported

package p

s := sum([1, "foo"])

Playground

Could be that there are more examples where the type isn't correctly inferred — I haven't looked into that. This was just something that I hit when working on Regal this evening.

@anderseknert anderseknert changed the title Type checker fails to identify type error from rule reference Type checker fails to identify type from reference Jan 16, 2025
@anderseknert
Copy link
Member Author

anderseknert commented Jan 16, 2025

Updated title as this also passes the type checker, so it's not just rule references that aren't identified:

allow := s if {
    a := "foo"
    s := sum([1, a])
}

@anderseknert
Copy link
Member Author

While I haven’t done a proper bisect, testing this out with some OPA binaries I had laying around, this bug is at least not a recent regression.

OPA v0.17.0(!!) correctly identifies this as a type error, but not OPA v0.30.0 or anything later I ran with. I did not test any version between those two, but I don't think it matters much. I'm surprised this hasn't been reported in all this time though! Fixing it would be great, as I'm sure those new to Rego and all the built-in functions are going to spend even more time than I did trying to understand what they did wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant