Repository navigation
fix(executor,lexer): #940 - redirect-failure diagnostics through ordered fd table; !+{ inside groups parses - #976
Merged
Merged
Conversation
…red fd table; `!`+`{` inside groups parses
R1: GNU redir.c:767-955 do_redirection_internal applies a compound's
redirect list in parse order and redir.c:135 redirection_error reports an
open failure through the fd-2 binding in force at the failing entry.
apply_command_output_redirects_inner ran its four stdio arms in field
order (out before err), so `( :; ) 2>cap.txt >bad` never performed the
earlier `2>` open (missing side effects, stale cap survived) and every
non-brace apply path reported through real stderr. The arms now run in
command.redirects parse order; failing_open_redirect_index extends
write_redirect_diagnostic_routed's `{target}: ` head-match to output-side
opens, and the ast_exec IoError arms route through it (unwrapping
`!`/`time`/`&` nodes), covering subshell/if/loop/case/select/simple/
function/exec/comsub faces.
R2: `{ ! { :; } >bad; echo inner; }` aborted the whole script: skip_brace
consumed `!` as non-word content so `{` after `!` was never a standalone
opener — the inner `}` closed the outer group, the fold produced an
unbalanced collapsed token and the parse failed EOF_COMPOUND with `>bad`
bound to the outer node. GNU: `!` is BANG (parse.y:2378 alist) and BANG
is in reserved_word_acceptable (parse.y:5913). A standalone `!` at a
command boundary now keeps the boundary open.
Also: execute_subshell_command_with_redirects early-returned on apply
failure without restoring the saved child state — leaked subshell_depth
and the reset_for_subshell_child env mutation.
Verified: nested-context-probes 56/56 divergences=0 (MSYS2 GNU 5.2.37
leg, WSL unavailable); ticket faces byte-identical to GNU;
issue846 tests 9/9, lexer 94/94, parser_tests 316/316.
Fixes #940
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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.
Summary
Fixes #940 — the residual faces of the #826/#846 redirect-failure family:
( )/simple faces:( :; ) 2>cap.txt >badnever performed the earlier2>open and reported to real stderr;true 2>cap.txt >badopened2>but still reported to real stderr. Root cause:apply_command_output_redirects_innerran the four stdio arms in FIELD order (out before err) instead of GNUdo_redirection_internal's parse-order walk (redir.c:767-955), and the open-failure reports bypassed the ordered fd-2 routing (redirection_error,redir.c:135/149-176). Fix: arms now run incommand.redirectsparse order (same contract asapply_brace_group_redirects); a newfailing_open_redirect_indexextendswrite_redirect_diagnostic_routed's{target}:head-match to output-side opens so every compound/dispatch IoError path reports through the fd-2 binding in force at the failing entry (incl.exec 2>filepersistent bindings and!/time/&wrapper unwrapping).!+ compound + redirect failure inside a group aborts the script:{ ! { :; } >bad; echo inner=$?; }died rc 1. Root cause:skip_brace'sprev_accepts_closetracker consumed!as non-word content, so a{after!was never a standalone opener and the inner}closed the outer group — the fold produced an unbalanced collapsed token →EOF_COMPOUNDparse error →>badbound to the outer node. GNU:!is BANG (parse.y:2378alist) and BANG is inreserved_word_acceptable(parse.y:5913), so the boundary stays open. Fixed by treating a standalone!at a command boundary as a boundary token.execute_subshell_command_with_redirectsearly-returned on apply failure without restoring the saved child state — leakedsubshell_depthand thereset_for_subshell_childenv mutation into the parent.Verification
scripts/audit/nested-context-probes.py56 probes: divergences 9 → 0 (oracle legGNU_CMD=D:/Git/bin/bash.exeMSYS2 GNU 5.2.37 — the documented non-WSL fallback; WSL unavailable to this runner).brace=1 d1-nonempty,paren=1 d2-nonempty,true=0 d3-nonempty,group-cont d4-nonempty, diagnostic on real stderr,nested=1 survived=0, rc 0.{ ! { :; } >bad; echo inner; }and the multi-line{ ! { :;\n}; echo; }now printinner=1(previously rc 1 abort / rc 2 syntax error).cargo test --test issue846_bang_redirect_regressions9/9,cargo test --lib lexer::94/94,cargo test --test parser_tests316/316.issue-846catalogue case verified byte-identical to GNU manually; manifest row promoted tomust-match.Test plan
Generated with Devin