Yes this is a bug, variable assignment only looks at the most recent scope, so the test=6 is skipped but the inner ones are not. Try the attached change please.
On Wed, 13 Nov 2024 at 06:46, Hugh Young <hughvonyo...@gmail.com> wrote: > Hello Nicolas and other friends, > Thank you for maintaining tmux -- it's a great composition. > I just found the group:) Before here I posted an [issue]( > https://github.com/tmux/tmux/issues/4234) on Tmux's Github page. > > I have no experience in how to format the code here. > Fortunately, the amount of code is not large, and I guess you can barely > see what I want to express. > > > cat t.conf > > L1=1 > L2=1 > test= > %if #{L1} > %if #{L2} > test=1 > %else > test=2 > %endif > test=5 > %else > %if #{L2} > test=3 > %else > test=4 > %endif > test=6 > %endif > display -p "test=#{test}" > > > tmux source t.conf > Expected output: > test=1 > Actual output: > test=3 > tmux -V > tmux 3.4/3.5a > > Is this a design or a bug? > > Thank you Nocolas :) > > Tuo > > -- > You received this message because you are subscribed to the Google Groups > "tmux-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to tmux-users+unsubscr...@googlegroups.com. > To view this discussion, visit > https://groups.google.com/d/msgid/tmux-users/CAAJZi8DMFbcB6Z70C7MmBHnRfQUxNynfG2zjbrUg2dPHC4F%3DDw%40mail.gmail.com > <https://groups.google.com/d/msgid/tmux-users/CAAJZi8DMFbcB6Z70C7MmBHnRfQUxNynfG2zjbrUg2dPHC4F%3DDw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "tmux-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+unsubscr...@googlegroups.com. To view this discussion, visit https://groups.google.com/d/msgid/tmux-users/CAEdLfcGgK_3oMA0vBJdYc4mY-uDjVrpBmDwhdKJob%2BiSF_szfA%40mail.gmail.com.
diff --git a/cmd-parse.y b/cmd-parse.y index 02e30550..fbed727b 100644 --- a/cmd-parse.y +++ b/cmd-parse.y @@ -223,9 +223,16 @@ assignment : EQUALS { struct cmd_parse_state *ps = &parse_state; int flags = ps->input->flags; + int flag = 1; + struct cmd_parse_scope *scope; - if ((~flags & CMD_PARSE_PARSEONLY) && - (ps->scope == NULL || ps->scope->flag)) + if (ps->scope != NULL) { + flag = ps->scope->flag; + TAILQ_FOREACH(scope, &ps->stack, entry) + flag = flag && scope->flag; + } + + if ((~flags & CMD_PARSE_PARSEONLY) && flag) environ_put(global_environ, $1, 0); free($1); } @@ -234,9 +241,16 @@ hidden_assignment : HIDDEN EQUALS { struct cmd_parse_state *ps = &parse_state; int flags = ps->input->flags; + int flag = 1; + struct cmd_parse_scope *scope; - if ((~flags & CMD_PARSE_PARSEONLY) && - (ps->scope == NULL || ps->scope->flag)) + if (ps->scope != NULL) { + flag = ps->scope->flag; + TAILQ_FOREACH(scope, &ps->stack, entry) + flag = flag && scope->flag; + } + + if ((~flags & CMD_PARSE_PARSEONLY) && flag) environ_put(global_environ, $2, ENVIRON_HIDDEN); free($2); }