Skip to content

Fix return in filter closure eval - #12292

Merged
sholderbach merged 2 commits into
nushell:mainfrom
sholderbach:fix-filter-closure-return
Mar 26, 2024
Merged

sholderbach merged 2 commits into
nushell:mainfrom
sholderbach:fix-filter-closure-return

Conversation

@sholderbach

Copy link
Copy Markdown
Member

Description

Closes #12257

This was down to the use of eval_block instead of eval_block_with_early_return. We may want to reconsider how we differentiate between this behavior. We currently need to check all the remaining commands that can invoke a closure block, if they properly handle ShellError::Return as a passing of a Value

  • Add test for return in filter closure
  • Fix use of return in filter closure

User-Facing Changes

You can now return a value from a filter closure

Tests + Formatting

Regression test

We need to use the `eval_block_with_early_return` more consistently!

Fixes nushell#12257

@IanManske IanManske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I think in the future it would be nice to refactor how closures are evaluated (e.g., a ClosureEvaluator). Sometimes we reset the env vars, and sometimes we don't. Sometimes we use eval_block and sometimes we use eval_block_with_early_return.

But this looks good, thanks!

@sholderbach
sholderbach merged commit 592dc4b into nushell:main Mar 26, 2024
@sholderbach
sholderbach deleted the fix-filter-closure-return branch March 26, 2024 16:50
@hustcer hustcer added this to the v0.92.0 milestone Mar 27, 2024
@sholderbach sholderbach added the notes:fixes Noted in "Bug fixes" section label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow return in closures

3 participants