Skip to content

Consolidate and fix closure parameter handling#16844

Merged
Bahex merged 12 commits into
nushell:mainfrom
nome:closures
Apr 23, 2026
Merged

Consolidate and fix closure parameter handling#16844
Bahex merged 12 commits into
nushell:mainfrom
nome:closures

Conversation

@nome
Copy link
Copy Markdown
Contributor

@nome nome commented Oct 10, 2025

  • Closures with optional, default or rest arguments can be used in more places.
    • Optional closure arguments or arguments with default values used to throw a "variable not found" error in most cases (except do).
    • Giving a closure with a ...rest parameter to a command like items used to have a bug, where only the last argument was given to the closure instead of a list of all arguments.
  • Some checks on closure arguments with type annotations, which used to only happen for do, now apply to all commands that take a closure. Consequently, there may be some corner cases where code that previously ran is now rejected.
  • Plugins which implement commands that handle closures probably have to be modified slightly (ClosureEval::add_arg now returns a Result).

Release notes summary - What our users need to know

Tasks after submitting

@nome nome force-pushed the closures branch 3 times, most recently from 77cdf2e to a6c64e9 Compare October 14, 2025 06:55
@nome nome marked this pull request as ready for review October 14, 2025 07:00
@Bahex Bahex self-requested a review April 23, 2026 04:54
nome and others added 9 commits April 23, 2026 07:56
Make `do` use the same closure calling logic as all other builtin
commands.

Implement handling of optional parameters, default parameter values and
parameter type checking in the common closure calling logic, which was
previously only implemented for `do`. Fix handling of rest parameters.

Fixes nushell#16179
Refactor command call handling to avoid code duplication with closure
calls.
@Bahex Bahex merged commit 48a40b6 into nushell:main Apr 23, 2026
17 checks passed
@github-actions github-actions Bot added this to the v0.113.0 milestone Apr 23, 2026
@Bahex
Copy link
Copy Markdown
Member

Bahex commented Apr 23, 2026

Sorry for taking so long to review and land it. This was a much needed refactor, thank you!

@fdncred fdncred added the notes:hide Noted only in "Full Changelog" section label May 13, 2026
@cptpiepmatz cptpiepmatz added notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes and removed notes:hide Noted only in "Full Changelog" section labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:refactor notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants