Skip to content

feat(builtins): add array.flatten - #797

Open
Anand Krishnamoorthi (anakrish) wants to merge 2 commits into
microsoft:mainfrom
anakrish:feat/array-flatten
Open

feat(builtins): add array.flatten#797
Anand Krishnamoorthi (anakrish) wants to merge 2 commits into
microsoft:mainfrom
anakrish:feat/array-flatten

Conversation

@anakrish

Copy link
Copy Markdown
Collaborator

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

  • Register array.flatten (arity 1) in src/builtins/arrays.rs
  • Iterate input array; spread nested arrays one level, copy non-array elements as-is
  • enforce_limit() on each output element to bound memory growth from adversarial inputs
  • Add array.flatten to docs/builtins.md

Tests

New tests/interpreter/cases/builtins/arrays/flatten.yaml covering: 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant