I did some experimenting and am confident on the fix. I don't know how to supply a patch suggestion officially, but have pasted it below. Four lines in parse.y need deleting. Arithmetic for loops should NOT be decrementing the 'word_top' variable, they do not make use of it. This also has flow on to select statements with nested arithmetic for loops, perhaps other statements too, I didn't look any further. My (albeit limited) testing has shown this fixes the line numbers for case statements and for loops.
diff --git a/parse.y b/parse.y index df1231da..3cf2c37f 100644 --- a/parse.y +++ b/parse.y @@ -843,25 +843,21 @@ arith_for_command: FOR ARITH_FOR_EXPRS list_terminator newline_list DO compound_ { $$ = make_arith_for_command ($2, $6, arith_for_lineno); if ($$ == 0) YYERROR; - if (word_top > 0) word_top--; } | FOR ARITH_FOR_EXPRS list_terminator newline_list '{' compound_list '}' { $$ = make_arith_for_command ($2, $6, arith_for_lineno); if ($$ == 0) YYERROR; - if (word_top > 0) word_top--; } | FOR ARITH_FOR_EXPRS DO compound_list DONE { $$ = make_arith_for_command ($2, $4, arith_for_lineno); if ($$ == 0) YYERROR; - if (word_top > 0) word_top--; } | FOR ARITH_FOR_EXPRS '{' compound_list '}' { $$ = make_arith_for_command ($2, $4, arith_for_lineno); if ($$ == 0) YYERROR; - if (word_top > 0) word_top--; } ;