Skip to content

Make Array.slice(start) JS-compatible by defaulting end#4061

Open
ATX24 wants to merge 7 commits into
canaryfrom
cursor/array-slice-js-compatibility-b003
Open

Make Array.slice(start) JS-compatible by defaulting end#4061
ATX24 wants to merge 7 commits into
canaryfrom
cursor/array-slice-js-compatibility-b003

Conversation

@ATX24

@ATX24 ATX24 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Pull Request Template

Thanks for taking the time to fill out this pull request!

Issue Reference

Please link to any related issues

  • This PR fixes/closes #N/A

Changes

Please describe the changes proposed in this pull request

  • Restored JS-compatible Array.slice(start) behavior while preserving existing slice(start, end) calls.
  • Added a BAML wrapper for Array.slice(self, start, end = self.length()) and moved native execution to _slice(self, start, end).
    • This avoids native default-argument omission issues (native functions do not run default-argument prologues).
  • Updated VM native implementation hook from slice to _slice.
  • Updated call binding behavior to allow positional arguments for defaulted parameters.
    • This is required so existing positional 2-arg calls remain valid when a trailing defaulted arg exists.
  • Added/updated array tests for one-arg slice behavior.
  • Updated affected snapshots for:
    • baml_src/arrays
    • compiler2_tir::phase3a::optional_param_call_binding_diagnostics
    • diagnostic_errors/optional_parameter_defaults

Testing

Please describe how you tested these changes

  • Unit tests added/updated
  • Manual testing performed
  • Tested in local Rust test environment

Commands run:

  • cargo test --package baml_tests --test baml_src
  • cargo test --package baml_tests optional_param_call_binding_diagnostics
  • cargo test --package baml_tests optional_parameter_defaults
  • cargo test --lib ⚠️ fails in this cloud environment due missing system link/runtime deps for unrelated targets (bridge_typescript N-API linker symbols / bridge_python python3.12 system lib).

Screenshots

If applicable, add screenshots to help explain your changes

[Add screenshots here...]

PR Checklist

Please ensure you've completed these items

  • I have read and followed the contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Additional Notes

Add any other context about the PR here

  • This change intentionally keeps compatibility for both slice(start) and existing positional slice(start, end) call sites.
Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features
    • Array slicing now supports calling slice(start) (end defaults to the array length) to return items from the specified start through the end.
    • Start-only slicing supports negative indexes for JavaScript-style behavior.
  • Bug Fixes
    • Optional/default parameters can now be passed positionally without incorrectly producing a “must be passed by name” diagnostic.
  • Tests
    • Added/updated array slice and type-checking test coverage for the new slice behavior and diagnostic expectations.

Co-authored-by: Dhilan Shah <ATX24@users.noreply.github.com>
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 16, 2026 10:03pm
promptfiddle Ready Ready Preview, Comment Jul 16, 2026 10:03pm
promptfiddle2 Ready Ready Preview, Comment Jul 16, 2026 10:03pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/array-slice-js-compatibility-b003

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

Co-authored-by: Dhilan Shah <ATX24@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 23.1 MB 9.8 MB file 22.8 MB +304.8 KB (+1.3%) OK
packed-program Linux 🔒 16.4 MB 6.9 MB file 16.3 MB +154.7 KB (+0.9%) OK
baml-cli macOS 🔒 17.8 MB 8.6 MB file 17.6 MB +252.5 KB (+1.4%) OK
packed-program macOS 🔒 12.8 MB 6.0 MB file 12.6 MB +116.3 KB (+0.9%) OK
baml-cli Windows 🔒 19.3 MB 8.7 MB file 19.2 MB +113.7 KB (+0.6%) OK
packed-program Windows 🔒 13.7 MB 6.1 MB file 13.5 MB +134.7 KB (+1.0%) OK
bridge_wasm WASM 15.3 MB 🔒 4.3 MB gzip 4.3 MB +25.7 KB (+0.6%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

Co-authored-by: Dhilan Shah <ATX24@users.noreply.github.com>
@cursor

cursor Bot commented Jul 16, 2026

Copy link
Copy Markdown

@coderabbitai review

Co-authored-by: Dhilan Shah <ATX24@users.noreply.github.com>
…e snapshot conflicts

Co-authored-by: Dhilan Shah <ATX24@users.noreply.github.com>
Co-authored-by: Dhilan Shah <ATX24@users.noreply.github.com>
Co-authored-by: Dhilan Shah <ATX24@users.noreply.github.com>
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

Creating the Deployment Timed Out.

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

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.

2 participants