-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 failure on referencing generated map with numeric keys #6736
Labels
Comments
anderseknert
changed the title
Type checker failure on referencing generated map with numeric keys inside some .. in iteration
Type checker failure on referencing generated map with numeric keys
May 7, 2024
Some further digging, and I've removed the "some .. in" constraint from the description as that wasn't required. package p
import rego.v1
nums[x] contains x if some x in [1, 2, 3]
bug if {
n1 := 1
nums[n1]
} ❯ opa eval -f pretty -d p.rego data.p
1 error occurred: p.rego:9: rego_type_error: undefined ref: data.p.nums[n1]
data.p.nums[n1]
^
have (type): number
want (one of): [__local2__] Using a numeric literal instead of a variable works: not_bug if {
nums[1]
} It seems to only happen for numeric keys, as the same policy works when using string keys: package p
import rego.v1
nums[x] contains x if some x in ["1", "2", "3"]
bug if {
n1 := "1"
nums[n1]
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to reference an item in a generated map by its numeric index in a
some .. in
iteration seems to have the type checker confused. I'd expect this to work:But it doesn't:
❯ opa eval -f pretty -d p.rego data.p 1 error occurred: p.rego:11: rego_type_error: undefined ref: data.p.nums[n1][__local6__] data.p.nums[n1][__local6__] ^ have (type): number want (one of): [__local2__]
The text was updated successfully, but these errors were encountered: