nushell / nushell/nushell

"Return into pipe" is allowed but doesn't use the pipe

Open
#13,648 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A:error-silent-fail A:syntax category:enhancement status:needs-triage
Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 19h
Merged PRs (30d)
85

Description

Describe the bug

The precedence of command vs pipe causes return x | y to bypass | y, which is un-intuitive IMO, even if it does what's written on the tin!
Ideally I'd love it to be special cased so it's equivalent to return (x | y).

Alternatively, nu could warn or even fail to compile because that's always a user mistake.

How to reproduce
use std assert

def oops [] {
  return "something" | str replace "some" "no"
}

def main [] {
  assert equal (oops) "nothing"
}
Expected behavior

Pass the above test, or produce an explicit warning/compile error.

Screenshots

No response

Configuration
key value
version 0.95.0
major 0
minor 95
patch 0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.78.0 (9b00956e5 2024-04-29) (built from a source tarball)
cargo_version cargo 1.78.0
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, system-clipboard, trash
installed_plugins
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported oops reproduction in Nushell 0.95.0 and inspect how return, command precedence, and pipelines are parsed and evaluated. Compare the requested behavior with the warning or compile-error alternative, then add a regression test showing that the pipeline is either applied or rejected explicitly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, shell
Domain
cli, compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.