You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
flags(bash): \local\ declared in a subshell narrows the parent shell's later writes #700
In f() { (local X=1); X=2; }; f; : "$X", the local runs in a child shell and ends with it, so X=2 writes the global X and the final read is satisfied. The scanner folds isLocal per (function, name) with a sticky OR, so the child-shell declaration narrows X=2 to the function's end. The final read then shows up as a false caller requirement.
Fix direction: record the declaration's execution scope (its child-shell range) as well as its function. A local should narrow only writes in the same shell environment. Ordinary local X; X=2 must stay function-scoped.
Repro (not yet run on a main build): the one-liner above in a .sh file, run with ripwire <dir> --flags. X should not be reported as a requirement.
Raised by CodeRabbit on #685 (thread) and deferred when #685 landed through #688.
Fixed in #720 (open; it closes this issue when it merges). Reported by jflowers.
The per-(function, name) fold no longer applies a sticky OR. A local now binds the name only from where it takes effect to where its own shell ends: the function's }, or sooner when it ran in a child shell. The scan already records that end on the write: the subshell's ), or the command end for a pipeline component or a background job. So f() { (local X=1); X=2; }; f; : "$X" no longer reports X. Neither do the $( local X ) and local X | cat forms. A plain local X; X=2 is still function-scoped.
Gate: test/bashenvcheck.sh arm 14 (test/bashenvfix/scope.sh):
SC_SUB, SC_CMD and SC_PIPE are red on main e267e24 and green on the lane.
Negatives: SC_PLAIN, SC_TWICE (a real local after a child-shell one), and SC_INNER / SC_NOLOC (writes inside a subshell) stay requirements. SC_PLAIN and SC_TWICE go red under a guard-off build.
Activity
joyful-ii-V-I commentedon Nov 22, 2026
Fixed in #720 (open; it closes this issue when it merges). Reported by jflowers.
The per-(function, name) fold no longer applies a sticky OR. A
localnow binds the name only from where it takes effect to where its own shell ends: the function's}, or sooner when it ran in a child shell. The scan already records that end on the write: the subshell's), or the command end for a pipeline component or a background job. Sof() { (local X=1); X=2; }; f; : "$X"no longer reports X. Neither do the$( local X )andlocal X | catforms. A plainlocal X; X=2is still function-scoped.Gate:
test/bashenvcheck.sharm 14 (test/bashenvfix/scope.sh):localafter a child-shell one), and SC_INNER / SC_NOLOC (writes inside a subshell) stay requirements. SC_PLAIN and SC_TWICE go red under a guard-off build.fix(flags): Bash scope honesty — a child shell's local and declare -g…
fix(flags): Bash scope honesty — a child shell's local and declare -g…
Merge pull request #720 from redhat-et/lane/flags-bash-cr685-r