GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Recommend the spread operator when a list is passed to a rest parameter by r00tkrnl · Pull Request #19679 · nushell/nushell

Conversation

@r00tkrnl

@r00tkrnl r00tkrnl commented Nov 28, 2026

Copy link
Copy Markdown

passing a list to rm used to say expected one of glob, string or cant convert list<string> to string with no hint

now it adds to pass each item of the list as a separate argument, spread it like so: ...$paths

the parse time path covers variables with a known type. the runtime path covers untyped params like def f [x] { rm $x }

tests in tests/commands/rm.rs cover both

closes #13755

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@r00tkrnl @codebuff-team
Recommend the spread operator when a list is passed to a rest parameter
9c4e120
A list given to `rm` failed with a bare type mismatch or a bare conversion
error. Both now say how to spread the list, naming the argument.

Refs nushell#13755

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
@github-actions github-actions Bot added the A:parser Issues related to parsing label Nov 28, 2026
@fdncred

fdncred commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

please use the PR template as we use it for making release notes

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fdncred
fdncred reviewed Nov 28, 2026
View reviewed changes

@fdncred fdncred left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

The parse-time hint names the right argument, and following it works for rm $paths and rm $x. The runtime hint takes its text from the value's span instead of the argument's, so subexpressions and $env lists get suggestions you can't type, and both paths suggest spreading lists whose items wouldn't fit anyway.

Findings: 1 High severity · 1 Medium severity · 3 Low severity

Open (5)
  • High severity Runtime hint names the wrong text for subexpressions and $env lists
  • Medium severity Hint suggests spreading when the items don't fit the rest parameter
  • Low severity Items from a spread are told to spread again
  • Low severity Every rest argument is copied twice on the success path
  • Low severity Same help text built in two crates

Notes from my clanker, checked on 9c4e120. CI ran only triage, so I built the branch and ran clippy with CI's flags on nu-engine, nu-parser and nu-command (clean), cargo fmt --all --check and typos (clean), cargo test -p nu-engine (42 passed), cargo test -p nu-parser (561 passed), cargo test -p nu-command (6750 passed) and the root repl::test_spread, test_custom_commands, test_known_external, test_signatures and test_type_check suites (327 passed). Each case ran on the branch binary and on main (dc352ef) under env -i. I tried the argument-span change locally to check the suggested fix. The clone thread is from reading the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/nu-engine/src/call_ext.rs
if let ShellError::CantConvert { help, .. } = &mut err
&& help.is_none()
{
let arg = String::from_utf8_lossy(engine_state.get_span_contents(value.span()));

@fdncred fdncred Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High severity Runtime hint names the wrong text for subexpressions and $env lists

On 9c4e120 the runtime hint takes its text from value.span(). That span points at wherever the list was made, not at the argument the user typed. When the list comes from a subexpression or the environment, the suggestion isn't something you can type:

rm (ls | get name)
# help: to pass each item of the list as a separate argument, spread it like so: ...get
rm (open list.json)
# help: ... spread it like so: ...open
rm (glob *.txt | each {|f| $f | path basename })
# help: ... spread it like so: ...each
rm $env.PATH
# help: ... spread it like so: ..."/usr/bin:/bin"
rm $nu.user-autoload-dirs
# help: ... spread it like so: ...$list

Main shows no help on any of these. The $env.PATH one copies the variable's value out of the host environment, so with a real PATH the help runs to a dozen lines. $list names a variable that doesn't exist.

The call already has the right span. Argument::Positional { span, .. } is documented as "the span encompassing the argument's usage within the call, distinct from the span of the actual value". I tried building the hint from it, walking self.arguments(stack) in rest instead of rest_iter_flattened, and got ...(ls | get name), ...(open list.json), ...$env.PATH and ...$nu.user-autoload-dirs. Both new tests still pass with that change.

The tests only use variables, where the value span and the argument span happen to match. A case like rm (ls | get name) would have caught this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/nu-parser/src/parse_calls.rs
/// Lists are not spread automatically, so a list given to a rest parameter fails to type
/// check. Build a hint that names the argument to spread.
fn list_needs_spread(working_set: &StateWorkingSet, arg: &Expression) -> Option<String> {
if !matches!(&arg.ty, Type::List(_)) {

@fdncred fdncred Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium severity Hint suggests spreading when the items don't fit the rest parameter

The hint fires for any list, even when spreading it would fail too:

let l = [{a: 1}]; rm $l
# help: to pass each item of the list as a separate argument, spread it like so: ...$l
let l = [{a: 1}]; rm ...$l
# Error: nu::shell::cant_convert
#   can't convert record<a: int> to string

The runtime path does the same. def f [x] { rm $x }; f (ls) suggests ...$x, and rm ...$x then fails on the first record.

list_needs_spread only checks for Type::List(_), and explain_list_argument only checks for Value::List. In the parser, pass expected in and return None unless type_compatible(&expected, item) holds for the list's item type. At runtime the check only has to run on the error path: add the help only when the list's items convert with T::from_value. The issue asked for the hint "when a list containing the correct type is given".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/nu-engine/src/call_ext.rs
stack: &mut Stack,
starting_pos: usize,
) -> Result<Vec<T>, ShellError> {
self.rest_iter_flattened(stack, starting_pos)?

@fdncred fdncred Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low severity Items from a spread are told to spread again

rest runs the hint on every value from rest_iter_flattened, including the items of a list that was already spread:

let x = [[a.txt] [b.txt]]; rm ...$x
# help: to pass each item of the list as a separate argument, spread it like so: ...[a.txt]

The user already wrote .... Another spread doesn't fix a nested list, flatten does. Only Argument::Positional values should get the hint. With rest walking self.arguments(stack) (the change from the span thread), skipping Argument::Spread items is one match arm, and I saw no help on this case with it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/nu-engine/src/call_ext.rs
.into_iter()
.map(T::from_value)
.map(|value| {
T::from_value(value.clone())

@fdncred fdncred Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low severity Every rest argument is copied twice on the success path

rest_iter_flattened already clones each value once, and T::from_value(value.clone()) now makes a second copy of every rest value of every built-in, only so the error path can look at it afterwards. For strings and binaries that is a full extra copy on every call, including rm ...$paths, run-external, exec and bytes build.

The argument walk from the span thread fixes this too: with rest reading self.arguments(stack), each value gets one val.clone() into T::from_value, and the hint uses the borrowed argument.

From reading the code; I didn't measure it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/nu-parser/src/parse_calls.rs
Comment on lines +470 to +474
let text = String::from_utf8_lossy(working_set.get_span_contents(arg.span));
let text = text.trim();
let text = if text.is_empty() { "$list" } else { text };

Some(format!(

@fdncred fdncred Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low severity Same help text built in two crates

list_needs_spread here and explain_list_argument in crates/nu-engine/src/call_ext.rs repeat the same message, the trim and the $list fallback, so the two can drift apart. AGENTS.md: "keep code duplication low without adding a pile of new helpers: reuse the helpers that already exist." One function in nu-protocol, next to ShellError::RECORD_SPREAD_DUPLICATE_HELP, that takes the argument text and returns the help would cover both call sites.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@fdncred fdncred fdncred left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

A:parser Issues related to parsing

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Change error message to recommend using the spread operator when passing a list to rm

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@r00tkrnl @fdncred
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.