feat(builtins): add array.flatten - #797
Open
Anand Krishnamoorthi (anakrish) wants to merge 2 commits into
Open
Conversation
Implements array.flatten, which performs one level of nesting removal on an array: nested arrays at the top level are inlined, while deeper nesting is left intact (matching OPA semantics). - Register array.flatten with arity 1 in builtins::arrays - Iterate input array; spread nested arrays one level, copy scalars as-is - Call enforce_limit() on each element to bound memory growth from adversarial inputs - Add YAML regression test covering: shallow, mixed-depth, empty, all-scalars, undefined element propagation, wrong type, and arg count Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…en coverage - Silence the pattern_type_mismatch/needless_borrowed_reference clippy conflict in array.flatten by matching on an explicit &Value::Array(ref nested) pattern, mirroring the existing convention in template_functions_collection.rs. This fixes the failing rust-clippy CI check (cargo xtask clippy, pinned to rustc 1.92.0). - Add tests/rvm/rego/cases/array_flatten.yaml, mirroring the interpreter fixture, to close the RVM coverage gap flagged in review. Type-check and arity 'bail!' errors are asserted as Undefined with allow_interpreter_incorrect_behavior: true, documenting RVM's existing non-strict builtin-error default (interpreter defaults to strict) rather than papering over the divergence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
array.flatten, which performs one level of nesting removal on an array: nested arrays at the top level are inlined, while deeper nesting is left intact — matching OPA semantics.Changes
array.flatten(arity 1) insrc/builtins/arrays.rsenforce_limit()on each output element to bound memory growth from adversarial inputsarray.flattentodocs/builtins.mdTests
New
tests/interpreter/cases/builtins/arrays/flatten.yamlcovering: shallow flatten, mixed-depth (inner nesting preserved), empty array, all scalars, undefined element propagation, wrong-type error, and argument-count error.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com