Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return in filter closure eval #12292

Merged
merged 2 commits into from Mar 26, 2024

Conversation

sholderbach
Copy link
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
Copy link
Member

@IanManske IanManske left a comment

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
15 checks passed
@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 pr:bugfix This PR fixes some bug label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:bugfix This PR fixes some bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow return in closures
3 participants