Repository navigation
fix(exec,declare): model GNU this_command_name lifecycle for expansion-time declaration diagnostics (Fixes #4161) - #4263
Merged
caomengxuan666 merged 1 commit intoNov 28, 2026
Conversation
…n-time declaration diagnostics (Fixes #4161)
caomengxuan666
deleted the
fix/4161-declare-rejected-local-copy-prolog
branch
November 28, 2026 08:53
This was referenced Nov 28, 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.
Summary
Model GNU Bash's dynamic
this_command_namelifecycle so expansion-time declaration diagnostics (nested_copy_refused,nested_readonly, array-conversion) use the exact GNUbuiltin_error_prologcommand label instead of deriving it fromfunction_name_stack(Fixes #4161).GNU C Specification
third_party/bash/execute_cmd.c:4617vs:4799-4800(execute_simple_command()): expands the word list before installingthis_command_name = words->word->word, so expansion-time declaration diagnostics on a function's first simple command still see the enclosing invocation's name (f).third_party/bash/execute_cmd.c:4951-4952: normal completion discards the unwind frame and setsthis_command_name = NULLunconditionally — subsequent simple commands in the same function therefore expand withthis_command_name == NULL(barer: readonly variableon line 4 oflocal r=(9); declare r=(4)).third_party/bash/execute_cmd.c:4629-4631: assignment-only (null) commands clearthis_command_name = NULLimmediately.third_party/bash/execute_cmd.c:3231,3931(execute_arith_command) and:4164(execute_cond_command):((and[[install their operator spelling and never clear it.this_command_nameintact.subst.c:12949 expand_declaration_argument()->variables.c:2658 make_local_variable()->builtins/common.c:240 sh_readonly()->builtins/common.c:83-94 builtin_error_prolog().Changes
src/shell/state.rs+src/executor/init.rs:this_command_nameandexpansion_command_name(Rc<RefCell<Option<String>>>) toShellState, deep-copied onClone(fork independence) and included inInteriorSnapshot(snapshot_interior/restore_interior).src/executor/command_execute.rs:"(("/"[["on arithmetic/conditional commands before dispatch (execute_cmd.c:3231/4164).ThisCommandNameGuardat the simple-command funnel to unconditionally clearthis_command_nameon exit (execute_cmd.c:4952), and cleared both cells on assignment-only null commands (execute_cmd.c:4629-4631).expansion_command_nameright before installingcmd.words[0]intothis_command_name(execute_cmd.c:4617vs:4800).src/executor/declare_local.rs:nested_copy_refused,nested_readonly, array-conversion) to readexpansion_command_nameinstead offunction_name_stack.first().tests/issues_3900_4199.rs+tests/issues_3900_4199/issue4161_this_command_name_lifecycle.rs:#4161repro, first-command invocation label, prior simple command NULLing, assignment-only NULLing,((/[[operator labels, pipeline/subshell preservation, nested function calls, and non-materialization of rejected local copies.What this PR deletes
same_scope_localsyntactic workaround predicate insrc/executor/declare_local.rs(obsoleted by the realexecute_cmd.c:4952this_command_namelifecycle).function_name_stack.first()expansion-time prefix fallback insrc/executor/declare_local.rs.Verification
/usr/local/bin/bash):eval,((,[[, comsub-assignment): 100% byte-exact (stdout + stderr + rc).RUSTFLAGS="-D warnings" cargo check --lib --locked: clean (0 warnings).cargo test --test issues_3900_4199 issue4161 --locked: 8/8 passed.cargo test --test issues_2500_2699 issue2658 --locked(#4123+#4160coverage): 23/23 passed.RUSTFLAGS="-D warnings" cargo check --lib --locked: clean (0 warnings).cargo test --lib --locked: 1,449/1,449 passed.cargo test --test issues_3900_4199 issue4161 --locked: 8/8 passed.cargo test --test issues_2500_2699 issue2658 --locked: 9/9 passed.python scripts/check-rustfmt.py(226 targets),check-marker-literals.py,check-api-ledger.py: all clean.Fixes #4161