Skip to content

fix(compat): converge compat-level plumbing - #1173

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/compat-plumbing
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/compat-plumbing

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1107, closes #1108. Root convergence: compat level becomes a single derivation (shopt flags in GNU mutex order win, else strict BASH_COMPAT parse NN/N.N in 31..53 else reset+keep-string+out-of-range diagnostic, default 53). shopt -s/-u now mutually exclusive + writes BASH_COMPAT back (oldval>44 keep-guard, readonly refuses write but still sets flag, rc 0); all bind/restore paths (bare/declare/local/export/readonly/read/temp-prefix/function-local restore/startup/unset) resync flags; conditional =~ reads the derived level. Assoc @/*: test -v/[[ -v ]] pass through in compat mode, bind path always literal-key. Tests: lib 699 + 30 new regression + shopt/unset/declare/assoc/array/cond suites green, executor_tests delta-free vs clean tree; 21 GNU parity probes + 10 scripts byte-identical. Known cosmetic: function-local restore of invalid values reports at the definition line.

GNU owners: builtins/shopt.def:654-741 set_compatibility_level /
set_compatibility_opts, variables.c:6457-6508 sv_shcompat,
version.c:54-55, builtins/set.def:974, arrayfunc.c:1152-1200 +
1511-1545 unbind_array_element / array_value_internal,
test.c:664-681 unary_operator -v, execute_cmd.c:4048-4057.

Root cause: the compat level was keyed on a loose BASH_COMPAT parse only
(support_names.rs, no strict spelling, no range check). shopt -s/-u
compatNN never synced it (BASH_COMPAT= never synced the flags back),
flags were not mutually exclusive, and bare shopt could not show a
BASH_COMPAT-driven level. unset VA_ALLOWALL and test -v AV_ATSTARKEYS
therefore only reacted to BASH_COMPAT spellings, never to shopt flags.

Single plumbing in src/builtins/shopt/compat.rs: a set compatNN flag wins
(GNU priority order), else the strict sv_shcompat parse (exact NN / N.N,
31..=default 53; invalid resets the level, keeps the raw string, reports
`compatibility value out of range`, assignment still status 0), else 53.
All readers (unset, test -v, [[ -v ]], =~ quoted-RHS) go through
compatibility_level(); shopt -s/-u rebinds BASH_COMPAT (mutual exclusion,
oldval>44 keep guard, readonly refusal without status change); every
bind/restore path (bare declare local export readonly read temp-prefix,
function-local restore, startup import, unset) re-syncs the flags.
Assoc test -v 'K[@]' is any-element under compat and a literal-key lookup
otherwise (bare @/* passes the -v rewrites unencoded only in compat
mode; bind paths always encode literally). Dual-store: the shopt BASH_COMPAT
rebind re-syncs the typed owner.

Verified: 30 new regression tests + 21-case byte-identical script-file
ledger vs bash 5.3.20 (stdout/stderr/rc); lib 698 green; related shopt /
unset / declare / assoc / array / cond suites green (executor_tests
failures are pre-existing platform ones, reproduced on stashed master).
@caomengxuan666
caomengxuan666 merged commit 42a6e3b into master Oct 23, 2026
6 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

Rebased onto post-#1181 master (b8d2331f) and force-pushed as 6a23eb52. Conflict notes: master's interim shell_compatibility_level_value/shell_compatibility_level_flag_aware helpers in src/executor/support_names.rs were dropped as duplicates — this PR's strict compatibility_level() (shopt/compat.rs) supersedes them, and master's new call sites were migrated to it. Master's set_option_inner/set_option_from_posix_walk split (#1055) was merged with this PR's Option<String> diagnostic return; master's POSIXLY_CORRECT import (#1054) kept alongside the new BASH_COMPAT flag sync in init.rs. cargo check + 30 regression tests + lib suite green.

@caomengxuan666
caomengxuan666 deleted the fix/compat-plumbing branch October 23, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant