Skip to content

shopt -u extglob mid-script leaves our parse-time extglob gate open: later +(a|b) parses as a group instead of GNU's ( operator syntax error #332

Closed

Description

@caomengxuan666

Summary

shopt -u extglob mid-script does not close our parse-time extglob gate (the rubash#131 extended_glob / token.extglob_gate mechanism): a later +(a|b) word still parses as an extglob group where GNU — whose parser reads each command AFTER the previous ones executed (parse.y:5466 gates group consumption on the live extended_glob) — reports the ( operator syntax error.

Repro (wt16/fix16 @ c12b8344, WSL GNU Bash 5.3.0 oracle)

# target/fix16/xt4.sh
shopt -s extglob
echo +(a|b)
shopt -u extglob
echo +(a|b)
echo done

GNU 5.3.0:

+(a|b)
<path>: line 4: syntax error near unexpected token `('
<path>: line 4: `echo +(a|b)'

rc=2 (nothing after runs).

rubash:

+(a|b)
<path>: line 4: syntax error near unexpected token `)'
<path>: line 4: `echo +(a|b)'

rc=2 — the group is still consumed at parse time (gate stayed open), so the error names ) instead of (.

Same divergence with an unclosed bracket after the unset (shopt -s extglob; shopt -u extglob; echo +(a|b[)* — GNU: syntax error near unexpected token '('; rubash: unexpected EOF while looking for matching ']' — the pre-#317 extglob-off subscript misfire, same root).

Owner

The parse-time extglob gate (src/lexer/scanner.rs extended_glob / extglob_split_pending, set_parse_extended_glob in src/builtins/shopt.rs:343-347) and the mid-script re-parse plumbing (token extglob_gate stamps, scanner.rs:975-977). Related known residue from #317: extglob-OFF diagnostics (echo +(a|b[)* outside any shopt) need extglob awareness in unclosed_input_close_char_posix (src/lexer/continuation.rs — captain-exclusive; lane report carries the proposal).

Original reporter: execdeep perf15 run (shopt -s extglob; shopt -u extglob residual state); target/perf15/b*.sh no longer exists in the main tree — the shapes above reproduce it deterministically (probes target/fix16/xt*.sh of wt16/fix16).

Activity

  1. added
    bug
    on Sep 29, 2026
  2. caomengxuan666 commented on Sep 30, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt18/misc17 (8f588f3a, master 9faaead): contrary to the issue framing, the #131 parse-time extglob gate DOES correctly track runtime toggles (proof: word splits at the paren with the gate closed; the case shapes already matched GNU). The real owner was the diagnostics layer: token_actions marked the argument-position paren as a parse error but returned Continue, so later lines parsed on and a stray-paren error OVERWROTE the first error - reporting ) instead of (. Fix: lone_word_function_head_candidate (parse.y:1054 LALR shift model - exactly one word then paren is a function-head candidate; ! prefix does not prevent it, assignment/redirect prefixes commit a simple_command so the paren reports) + push_unexpected_token_error_named (GNU virtual newline token) + the arm now pushes the error node and Breaks (first error stops the remaining input, parse.y:6724/6833). 25-form matrix byte-identical to WSL GNU 5.3.0 incl. both issue reproducers, single-line toggles, no-shopt bare forms, !/assignment/redirect prefixes, function bodies, first-error-wins, gate-regon positive; extglob suites stay at the 16 environment-class lines with zero syntax-error lines. 12 regressions. Leftovers for other owners: the +(a|b[)* prescan shapes (captain continuation proposal, verified in-lane), echo () body diagnostic, echo ( EOF naming.

  3. added a commit that references this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions