Skip to content

Fix spread arguments in dynamic % dispatch - #9

Closed
i-api wants to merge 1 commit into
fdncred:dynamic_percent_cmdsfrom
i-api:fdncred/dynamic_percent_cmds
Closed

i-api wants to merge 1 commit into
fdncred:dynamic_percent_cmdsfrom
i-api:fdncred/dynamic_percent_cmds

Conversation

@i-api

@i-api i-api commented May 5, 2026

Copy link
Copy Markdown

Commit 1810072 ("implement dynamic dispatch for % sigil") added runtime dispatch for %($cmd) / %$cmd, but the parser loop that handles trailing arguments only emitted Argument::Positional. It never checked for the ... spread prefix, so ...$args was parsed as a literal value and resolved as a file path at runtime:

export def --wrapped builtin [arg1, ...args] { %($arg1) ...$args }
builtin ls .
# => Error: nu::shell::io::not_found
# "/Users/.../nushell/...$args" does not exist

The fix mirrors how spread is detected everywhere else in the parser (internal calls, external calls, list/record literals): check whether the span starts with ... followed by $, [, or (, strip the three-byte prefix, parse the remainder as List(Any), and push Argument::Spread instead of Argument::Positional. The IR compiler already forwards spread arguments faithfully to run-internal, and call.rest() flattens them at runtime, so no other changes are needed.

Commit 1810072 ("implement dynamic dispatch for % sigil") added
runtime dispatch for `%($cmd)` / `%$cmd`, but the parser loop that
handles trailing arguments only emitted `Argument::Positional`. It
never checked for the `...` spread prefix, so `...$args` was parsed
as a literal value and resolved as a file path at runtime:

    export def --wrapped builtin [arg1, ...args] { %($arg1) ...$args }
    builtin ls .
    # => Error: nu::shell::io::not_found
    # "/Users/.../nushell/...$args" does not exist

The fix mirrors how spread is detected everywhere else in the parser
(internal calls, external calls, list/record literals): check whether
the span starts with `...` followed by `$`, `[`, or `(`, strip the
three-byte prefix, parse the remainder as `List(Any)`, and push
`Argument::Spread` instead of `Argument::Positional`. The IR compiler
already forwards spread arguments faithfully to `run-internal`, and
`call.rest()` flattens them at runtime, so no other changes are needed.
@fdncred

fdncred commented May 5, 2026

Copy link
Copy Markdown
Owner

Thanks. I've created a slightly different set of changes for this functionality in the PR.

@fdncred fdncred closed this May 5, 2026
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