[Feature] Implement array slicing and concatenation. #29061
Draft
+783
−25
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.
Motivation
This PR adds array slicing and concatenation support to Leo, enabling more expressive and convenient array manipulation.
Array Slicing allows extracting a contiguous portion of an array using Rust-like syntax:
Array Concatenation allows combining two arrays with matching element types using the
+operator:Both features are resolved at compile time - slices and concatenations are expanded to individual element accesses, ensuring no runtime overhead.
Test Plan
Slicing Tests:
slice_basic.leoarr[2..5]exclusive end sliceslice_inclusive.leoarr[2..=5]sliceslice_from_start.leoarr[..5]sliceslice_to_end.leoarr[3..]sliceslice_full.leoarr[..]slice_with_variables.leoslice_out_of_bounds_fail.leoslice_invalid_range_fail.leoConcatenation Tests:
array_concat.leoa + b, nested arrays, different sizesarray_concat_chained.leoa + b + carray_concat_with_slice.leoa[0..2] + b[2..4]array_concat_type_mismatch_fail.leoRelated PRs