Repository navigation
fix(builtins): report each missing declare -p name once, in operand order - #3378
Merged
Merged
Conversation
…rder In -p mode there were two reporting sources for invalid-identifier operands: the validation loop reported first (before all other diagnostics) and the print loop reported again in operand order, so 'declare -p nope1 -x nope2' printed -x, nope1, -x, nope2 and 'declare -p x --help' re-reported --help. The validation loop no longer reports or drops invalid names in -p mode; they flow into assign_names and the print loop becomes the single reporter in operand order. GNU declare.def:389-406 does one loop, one report, in place order. typeset -p is fixed by the same mechanism; declare -f -p was already correct. Refs unixwin#3345 Regression pin tests/issue3345_declare_p_missing_name_report_order.rs (21 tests; fail-first 5 passed / 16 failed on the unpatched tree, 21/21 pass after; supervisor verified both rounds with the patch method). Declare family 110/110, local-related 21/21. cargo fmt clean.
This was referenced Nov 13, 2026
caomengxuan666
marked this pull request as ready for review
November 14, 2026 03:50
This was referenced Nov 14, 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.
Fixes #3345
What was fixed
declare -preported missing names in the wrong order and twice: each name should be reported exactly once, in operand order, anddeclare -p x --helpshould not re-report--help.In
-pmode there were two reporting sources for invalid-identifier operands (option-shaped names-x/-a/-p/-n/+x,--,--help,X(BR),a[],a[bad): the validation loop reported first ({name}: not found, ahead of all other diagnostics) and the print loop (print_declare_names) reported again in operand order. Measured:declare -p nope1 -x nope2printed-x,nope1,-x,nope2;declare -p x --helpprinted--help,x,--help.The fix touches only
src/builtins/declare.rs(+26/−12, one line of logic): in-pmode the validation loop no longer reports and no longer drops invalid names — they flow intoassign_namesand the print loop becomes the single reporter, in operand order. Deleting the report without letting the names through would have broken the all-invalid-operands shape (namesempty triggers the early return before the print loop runs). The non--pnot a valid identifierpath is untouched.typeset -pis fixed by the same mechanism;declare -f -pwas already correct.GNU (
builtins/declare.def:389-406): theif (pflag)branch walks operands in order throughshow_name_attributes, reports a missing name immediately withsh_notfound, and incrementsany_failed— one loop, one report, in place order. That is GNU's assembly order.What was deleted
Nothing. No files, features, or tests were removed.
Verification (all run, per-item counts)
tests/issue3345_declare_p_missing_name_report_order.rs: 21/21 pass (expectations from GNU 5.3.20 measurements; covers operand order,--helponce/centered/repeated,--,-p/-a/-A/-n/+xas operands,X(BR)single/all,dv=6,X(BR)=1,a[1]/a[]/a[bad, typeset same-order, exit code 1). Fail-first on the unpatched tree (supervisor re-ran with the patch method): 5 passed / 16 failed — every double-report/wrong-order shape was red; the green ones were shapes already correct (singleX(BR), all-invalid,dv=6, subscript-name order, lone--).third_party/bash): 4 probe scripts (~40 shapes) underenv -i; after the fix probe 4 is zero-diff and the rest match except the noted noise below.cargo test --lib declare7/7 green; local-related 4 files 21/21 green.cargo build -j 2clean,cargo fmt --checkclean.src/lexer/continuation.rsuntouched.Owed
local -pstill differs on two shapes (a different mechanism:execute_local's pre-pass reports missing plain names first and deletes them from args, and its guard then swallows trailing option-shaped operands):local -p nope1 -x(GNU reports-x, rubash misses it) andlocal -p x --help(GNU reports--help, rubash misses it). The double-report onlocal -p v nope1 -xis already gone with this fix. Fixing it needs restructuring the pre-pass report assembly (frame-scope adjudication + operand-order merge) — suggest a separate issue.2>&1stdout/stderr interleaving:declare -p v nope1 -x nope2 w— GNU interleaves per name (vprint →nope1→-x→nope2→wprint); rubash emits all of stdout before all of stderr (a repo-level known limitation of buffered builtin output). Each stream's own order already matches GNU; the pin asserts per stream. Fixing it means touching the buffered-output plumbing, out of scope.BASHpath andFUNCNAMErendering differences are pre-existing and unrelated.