Repository navigation
fix(parser): coproc rejects '!' in command position as a syntax error (rubash#1652) - #1693
Conversation
|
Thanks for this PR — we verified it on your tree (cherry-picked onto master 160e792, full build + probes against the GNU bash 5.3.20 oracle). Your own tests pass (6/6, plus parser 31/31), and 5 of 6 probe shapes match GNU byte-for-byte. One shape does not, and it is a real divergence:
Reading the diff, the cause looks structural: the name-collection check that rejects reserved words / operators in coproc position has no exemption for a leading assignment word, so Could you add the assignment exemption to the collection check and a regression test for this shape? Once that lands we will re-verify this one shape and merge — everything else in the PR is already green on our side. (For context: our in-house slice for the same issues is being stood down in favour of your PRs wherever they verify, which is why several sibling coproc PRs of yours were merged today.) |
… (rubash#1652)
GNU parse.y:1125-1175 coproc grammar is COPROC [WORD]
shell_command, and '!' is a pipeline modifier, not a
shell_command, so 'coproc ! ...' is a syntax error (rc 2).
Rubash collected the '!' as a simple-command word and ran
the coproc with the negation silently applied inside the
child.
Two positions error, both verified against GNU bash 5.3.20:
- body position: 'coproc ! ...' (the '!' keyword is also
excluded from NAME candidacy, so 'coproc ! { ...; }' no
longer falls through to the runtime 'not a valid
identifier' error);
- second word of the simple command: 'coproc a ! ...',
'coproc NAME ! ...' (after COPROC WORD the parser commits
to the named form and demands a shell_command).
A '!' after two or more words stays a plain word ('coproc
a b ! c', 'coproc echo hi !'), as does a quoted '!'.
The error reuses the __RUBASH_PARSE_ERROR_NEAR__ node shape
(case #1641): the executor reports 'syntax error near
unexpected token `!\'' with the offending line echoed and
aborts the script at that line with status 2.
Regression tests:
tests/issue1652_coproc_bang_syntax_regressions.rs (6 tests).
c1d4f62 to
70689f6
Compare
…ection (rubash#1983) GNU's lexer returns an assignment-shaped first word as ASSIGNMENT_WORD, and parse.y:5899 reserved_word_acceptable has no ASSIGNMENT_WORD in its accept set, so a `!` after `coproc X=1` never becomes BANG — it lexes as a plain WORD and lands as the child command's name (GNU bash 5.3.20: the child reports `!: command not found`, script rc 0). The #1693 implementation of the #1652 rejection fired for every one-word collection, so the GNU-legal spaced shape `coproc X=1 ! echo hi` was rejected rc 2. Exempt assignment-shaped first words (name / name[subscript], optional `+`, then `=`), judged on the raw spelling — a quoted name is not an assignment word in GNU either. Non-name shapes (`9a=1`, `a-b=1`) stay WORDs and keep the rc-2 rejection. The word_metadata Vec gets an explicit element type: the exemption reads [0].raw before the first push, which leaves the element type ambiguous to inference (E0282). Judgment shape first measured in the #1712 line's 537e177. Regression pins: tests/issue1983_coproc_assignment_bang_regressions.rs (X=1 / a+=1 / _a9= spaced forms, a[1]=x subscript form, 9a=1 / a-b=1 negative controls, glued X=1! control). The pins assert the parse-admission face only; the coproc wait status after the output fd drains is a separate, pre-existing reap-face race (GNU deterministically reports 0 there) and is deliberately not pinned here.
Fixes #1652.
GNU parse.y:1125-1175 coproc grammar is
COPROC [WORD] shell_command, and!is a pipeline modifier, not a shell_command, socoproc ! ...is a syntax error (rc 2). Rubash collected the!as a simple-command word and ran the coproc with the negation silently applied inside the child.Two positions error, both verified against GNU bash 5.3.20:
coproc ! ...(the!keyword is also excluded from NAME candidacy, socoproc ! { ...; }no longer falls through to the runtime 'not a valid identifier' error);coproc a ! ...,coproc NAME ! ...(after COPROC WORD the parser commits to the named form and demands a shell_command).A
!after two or more words stays a plain word (coproc a b ! c,coproc echo hi !), as does a quoted!.The error reuses the
__RUBASH_PARSE_ERROR_NEAR__node shape (case #1641): the executor reportssyntax error near unexpected token \!'` with the offending line echoed and aborts the script at that line with status 2.Notes from the investigation, deliberately out of scope here:
coproc time ! ...also errors in GNU but is still accepted here: it goes through the separate time-prefix coproc path, andcoproc time <simple>itself diverges (GNU runs it as a simple command whose argv[0] istime, i.e. 'time: command not found' in the child; rubash runs a timed pipeline). That path needs its own issue.coproc \"!\" { ...; }) prints a lexer marker byte before the!in the 'not a valid identifier' diagnostic (verified identical on master).Verification (local, master 499a5e2 + this fix, vs GNU):
coproc ! echo hi,coproc a ! b,coproc NAME ! echo hi,coproc ! { echo hi; }, barecoproc !) all produce GNU-identical diagnostics and exit 2; earlier script lines run, later lines do not.