IR: allow subexpression with redirection.#15617
Merged
sholderbach merged 4 commits intonushell:mainfrom Apr 24, 2025
Merged
Conversation
sholderbach
reviewed
Apr 23, 2025
Member
sholderbach
left a comment
There was a problem hiding this comment.
Thanks for quickly coming up with a new approach Wind!
The structure in the compiler seems plausible to me but I am confused by the test.
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
sholderbach
approved these changes
Apr 24, 2025
fixerer
pushed a commit
to fixerer/nushell
that referenced
this pull request
Sep 13, 2025
*Description* Attempt to fix issue [nushell#16582](nushell#16582) by avoiding duplicated `write` and `close` calls for an `out>`/`err>` redirected file for `try-catch` and `if-else` blocks. Similarly to [this PR](nushell#15617) a function to identify if a code block is being handeled, and if so skip the invocation of `finish_redirection` so that no additional writes are added. (The blocks perform redirections on their own and this then avoids the duplication). *User-Facing Changes* The following commands will no longer raise ir-eval errors: - `if true { echo "hey" } out> /dev/null` - `if false { echo "hey" } else { echo "ho" } out> /dev/null` - `try { 1/0 } catch { echo "hi" } out> /dev/null` *Tests* Added 8 tests.
WindSoilder
pushed a commit
that referenced
this pull request
Sep 19, 2025
### Description Attempt to fix issue [#16582](#16582) by avoiding duplicated `write` and `close` calls for an `out>`/`err>` redirected file for `try-catch` and `if-else` blocks. Similarly to [this PR](#15617) a function to identify if a code block is being handeled, and if so skip the invocation of `finish_redirection` so that no additional writes are added. (The blocks perform redirections on their own and this then avoids the duplication). ### Release notes summary - What our users need to know The following commands will no longer raise ir-eval errors: - `if true { echo "hey" } out> /dev/null` - `if false { echo "hey" } else { echo "ho" } out> /dev/null` - `try { 1/0 } catch { echo "hi" } out> /dev/null` IR before changes: [before.txt](https://github.com/user-attachments/files/22308084/before.txt) IR after changes: [after.txt](https://github.com/user-attachments/files/22308085/after.txt) ### Tests Added 8 tests. - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` --------- Co-authored-by: Fixerer <fixerer@example.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Try to fixes #15326 in another way.
The main point of this change is to avoid duplicate
writeandclosea redirected file. So during compile, if compiler know current element is a sub-expression(defined by privateis_subexpressionfunction), it will no longer invokefinish_redirection.In this way, we can avoid duplicate
finish_redirection.User-Facing Changes
(^echo aa) o> /tmp/aaawill no longer raise an error.Here is the IR after the pr:
Tests + Formatting
Added 3 tests.
After Submitting
Maybe need to update doc nushell/nushell.github.io#1876