Skip to content

[bug] shopt -s extglob inside a SOURCEd file breaks parsing of subsequent 'function NAME()' headers: syntax error near '(' (GNU accepts) — breaks OMB svn completion #302

Closed

Description

@caomengxuan666

Found by the ecosweep lane (wt10/ecosweep, 2026-09-28) running the oh-my-bash completions matrix (rubash e207b0d; 59 completions, one red: svn).

Minimal reproducer (script file, both shells)

b18-extglob-fn.sh:

shopt -s extglob
function f()
{
  :
}
echo OK

Driver (b18b.sh): source b18-extglob-fn.sh; echo done=$?

  • GNU bash 5.3.0 (WSL /usr/local/bin/bash): prints OK, done=0.
  • rubash: b18-extglob-fn.sh: line 2: syntax error near unexpected token '('
    (and line 2: function f()), done=2.

Executing the same file directly as a script is fine on both shells (rubash b18-extglob-fn.sh → OK); rubash -n on it is also clean. The failure needs the
source path: the shopt -s extglob executed mid-source changes parser state so the
next function NAME() header's ( is rejected.

Real-world impact

  • oh-my-bash completions/svn.completion.sh:40 does shopt -s extglob; line 45 is
    function _svn_read_hashfile() → sourcing the completion under rubash dies with
    line 45: syntax error near unexpected token '('; _svn never defined
    (target/issue-suites/results/ecosweep/omb/completions/svn.err). GNU sources the same
    file cleanly (verified on the LF copy, rc=0). 58/59 other OMB completions source OK.
  • Any bash-completion-style file that flips extglob on before defining functions is
    affected — that is a common upstream idiom (bash-completion's own files do
    shopt -s extglob via _comp_enable_extglob).

GNU C anchor

shopt -s extglob sets the parser flag for subsequent reads; GNU's reader
(parse.y yylex / read_token_word with sh_syntaxtab extended-class bits) applies
extglob only where a pattern word can appear — a function-definition header
(parse.y function_def production, function WORD ()) is parsed by the grammar before
pattern-word treatment, so () after the name stays legal. The rubash source-mode
reader applies the extglob word rules at the grammar position of the header.

Over-strict class relative to #222 (GNU-valid constructs rejected), but a distinct
trigger (source + runtime extglob + function header).

Artifacts

  • target/issue-suites/results/ecosweep/probes/b18-extglob-fn.sh + b18b.sh (+ cmp .rb/.gnu outputs)
  • target/issue-suites/results/ecosweep/omb/completions/svn.{out,err,rc}

Activity

  1. added
    bug
    gnu-baseline
    on Sep 28, 2026
  2. added 2 commits that reference this issue on Sep 28, 2026
  3. caomengxuan666 commented on Sep 28, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt11/lexmix (a5ae33b4, master): the extglob attribution was a MISDIAGNOSIS — the v5 repro fails with no shopt at all. Real root: stdin_source_is_function_signature's paren-stripping arm reduced function f() to function f (not a single WORD) and returned false outright, never reaching the keyword-form check — the group broke after the header line in every incremental reader (source builtin, piped stdin); whole-text paths (direct exec, eval) passed, which is why ecosweep's harness missed it. Now a fall-through with a function_keyword_operand_name() that strips the optional () while validating the whole operand (parse.y:1054-1061 function_def productions, incl. FUNCTION WORD '(' ')' newline_list function_body at :1056). Same-family residue in parser/function_command.rs: function f g now produces GNU's syntax error rc=2 instead of 'function: command not found' (g1-g5 byte-identical). Verification: 11-case sourced function-header matrix, the REAL oh-my-bash svn.completion.sh (49944B) sources clean with _svn defined; 12 new regressions; 505/505 lib.

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

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions