Repository navigation
fix(parser): accept function-def name words containing unquoted $( ) (#462) - #476
Merged
Merged
Conversation
…(rubash#462)
GNU function_def (parse.y:1054) admits ANY single WORD before `()`, and
read_token_word folds an unquoted `$( ... )` into the current word
(parse.y:5513-5532), so `f$()g() { :; }` parses; the expanded name is
validated only at definition time (valid_function_word). rubash's parser
rejected such words because the substitution text's `(`/`)` tripped the
word-structure character check, breaking zZshFramework files.sh.
- parser/support.rs: mask `$(`/`${`/`$[` and backquote spans before the
function-name structure checks (is_function_name /
is_function_keyword_name); bytes inside a span are substitution text,
not word structure.
- parser/parse_loop.rs: admit Variable/CommandSubst tokens at the
function-definition gate (`$x() { :; }`, `$(echo f)() { :; }` lexes the
name as its own token kind).
- executor/function_calls.rs: a raw name carrying a backquote span is
definition-time invalid, matching GNU's
`` `echo f`': not a valid identifier'``.
Runtime behavior matches the GNU 5.2.37 msys oracle byte for byte:
definitions parse (`-n` rc=0) and names containing expansions are
rejected non-fatally with `` `RAW': not a valid identifier'`` (rc=1),
execution continuing. tests/issue462_funcdef_name_cmdsub_regressions.rs
pins the issue's boundary table, the keyword/backtick forms, break
characters outside the span, and the assignment-prefix (#453) control
row. cargo fmt also reflows a pre-existing path.rs test to satisfy the
fmt gate.
Oracle: D:\Git\usr\bin\bash.exe (GNU bash 5.2.37 msys), 2026-10-10.
Closes #462
This was referenced Oct 10, 2026
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.
Closes #462.
Problem
f$()g() { :; }was rejected byrubash -nwithsyntax error near unexpected token '('while GNU bash parses it:function_def(parse.y:1054) admits any single WORD before(), and read_token_word folds an unquoted$( ... )into the current word (parse.y:5513-5532$(' branch). This broke the real-world harvest casefileRemoveWithOverwrite-dirOrFile$(useWithCaution)__hsl() { ... }in gingerpaledale/zZshFrameworkfiles.sh`.Fix (GNU semantics: name is a WORD; the expanded name is validated at definition time)
parser/support.rs: mask$(/${/$[and backquote spans before the function-name word-structure checks — bytes inside a substitution span are substitution text, not word structure.parser/parse_loop.rs: admitVariable/CommandSubsttokens at the function-definition gate ($x() { :; },$(echo f)() { :; }— the name lexes as its own token kind).executor/function_calls.rs: a raw name carrying a backquote span is definition-time invalid, matching GNU's`echo f`': not a valid identifier'.Oracle
Every expectation measured against GNU bash 5.2.37 msys (
D:\Git\usr\bin\bash.exe) on 2026-10-10, corroborating the issue's WSL GNU 5.3.0 table:f$()g() { :; }-nok; runtime`f$()g': not a valid identifier'rc=1, continues$x() { :; }/$(echo f)() { :; }function f$()g { :; }/ backtick formf$();g() ...)fruns,gdefinedTests
New
tests/issue462_funcdef_name_cmdsub_regressions.rs(14 tests) pins the issue boundary table, keyword/backtick forms, structure checks, and the definition-time identifier error. Existing suites green: issue443 (16), issue461 (12), issue314, parser (316), lexer (72), assign-prefix (#453) regressions. The 7 remaining failures (pwd/path, parameter_transform, pb10k interactive, upstream snapshot slice) reproduce identically on the base commit cd98dd9 — environment-dependent, unrelated.Note: cargo fmt also reflows one pre-existing
src/executor/path.rstest to satisfy the pre-commit fmt gate.