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
[bug] Multi-line function definition nested in a loop inside a function fails to parse (syntax error; GNU accepts) — kills liquidprompt test_disk/test_ram at rc=2 #314
rubash fails to PARSE a multi-line function definition nested directly inside a loop body, when the loop itself is inside a function. GNU bash 5.3.0 parses and executes it fine. One-line function definitions in the same position parse fine on rubash; the multi-line body alone (without the outer function wrapper) also parses fine — the failure needs all three ingredients: (1) enclosing function, (2) loop (for ((;;)), for-in, while), (3) multi-line g() { … } body.
Found by the ecosweep2 lane running liquidprompt's own shunit2 suite: tests/test_disk.sh and tests/test_ram.sh both define a mock function (df() { printf …; }) as the first statement of a for (( i=0; i < ${#outputs[@]}; i++ )) loop inside function test_disk { — both files die at parse time (syntax error: ';' unexpected / syntax error: (( i=0; … ))), rc=2, zero tests run. GNU runs them green.
Minimal reproducer (6 lines, script file)
f() {
forxin a b;dog() {
echo
}
done
}
GNU 5.3.0 (wsl /usr/local/bin/bash -n): rc=0
rubash (release @116b12aa): syntax error: unexpected end of file from '{' command on line 3, rc=2
With for (( i=0; i < 3; i++ )) instead of for x in, rubash instead reports line 2: syntax error: ';' unexpected + (( i=0; i < 3; i++ )) — two renderings of the same desync depending on loop flavor.
Variant matrix (rubash rc for -n; GNU rc=0 on every row)
shape
rubash
wrapper fn + for ((;;)) + multi-line nested g(){…}
CRASH
wrapper fn + for x in + multi-line nested
CRASH
wrapper fn + while read + multi-line nested
CRASH
f() {-syntax wrapper instead of function f {
CRASH (same)
wrapper fn + loop + ONE-LINE nested g() { echo; }
ok
wrapper fn + loop + non-function multi-line body
ok
NO wrapper fn + loop + multi-line nested g(){…}
ok
nested funcdef with ${#arr[@]} in the for-arith condition (test_disk exact shape)
CRASH
GNU C source anchor (vendored third_party/bash)
parse.y:1054-1061 function_def productions (WORD '(' ')' newline_list function_body, FUNCTION WORD newline_list function_body) — a function definition is an ordinary compound command element in simple_command/body positions; nothing about a loop body inside a function restricts nested definitions. parse.y:419 grammar types; body parsed via the same parse_compound_command path as top level.
Fixed by wt13/sweepfix (54349c7a, master 203c2b5): the LOOP frame accepted ANY boundary close-brace as terminator (for the for x; { } brace-form), so a nested g() { ... } close-brace was double-counted - popping the loop frame AND decrementing the outer function group depth, truncating the function body at the nested brace. Frame-exact pairing per parse.y:1054-1061 function_def + :879-880 (two body forms; after do only done closes). Both repros + 11-shape matrix + execution semantics pass; liquidprompt test_disk/test_ram rc=2 -> rc=0.
Activity
docs(corpus): ecosweep2 lane section — second-pass fine-grained corpu…
fix(#314): nested multi-line funcdef in loop-in-function parses - fra…
caomengxuan666 commentedon Sep 29, 2026
Fixed by wt13/sweepfix (54349c7a, master 203c2b5): the LOOP frame accepted ANY boundary close-brace as terminator (for the for x; { } brace-form), so a nested g() { ... } close-brace was double-counted - popping the loop frame AND decrementing the outer function group depth, truncating the function body at the nested brace. Frame-exact pairing per parse.y:1054-1061 function_def + :879-880 (two body forms; after do only done closes). Both repros + 11-shape matrix + execution semantics pass; liquidprompt test_disk/test_ram rc=2 -> rc=0.