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

Duplicate entry/key in set or map #162

Closed
anderseknert opened this issue Jun 13, 2023 · 2 comments
Closed

Duplicate entry/key in set or map #162

anderseknert opened this issue Jun 13, 2023 · 2 comments

Comments

@anderseknert
Copy link
Member

This is almost certainly a mistake, and the user probably intended some other key/value in its place:

# duplicate "admin" value
required_roles := {"admin", "developer", "devops", "admin"}

# duplicate "username" key
user := {"username": "eddie", "claims": [], "username": "jane"}

This is an interesting one as the parser eradicates the duplicates, so we won't see this in the AST. For sets this just means an item is removed — for maps it's potentially worse as the value could differ too, and you don't know which one you'll get.

Not sure how to best approach this. Since we do have the location of the set or map, perhaps we could add a custom built-in function that scanned the source code (which is available in evaluation already) from that location? Can probably use the tokenizer from OPA.

It's fine to only consider top level items if it simplifies the implementation, i.e. not duplicates in nested map structures.

@anderseknert
Copy link
Member Author

Created issue in the OPA backlog to have Text included in Location when requested. This would help us parse the text of these sets / objects without having to include the scanner code from OPA, which would need to be copy-pasted as it's marked as internal.

@anderseknert
Copy link
Member Author

I learnt some day ago that the formatter will have these erased, so this is sorta covered by the opa-fmt rule. While I don't like relying on that, it does make this less interesting to pursue given the effort required. I'll close this for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

1 participant