Bytecode machinery to handle compile epoch bumps is not right.
% proc demo a {upvar 1 $a[proc upvar args {puts WOW}] b}
% demo v
%
Should print "WOW"
Contrast with:
% proc demo a {set u upvar; $u 1 $a[proc $u args {puts WOW}] b}
% demo v
WOW
%
I think it may be a false reasoning...
In this case more interesting the question "When exactly the command resolving should take place - before or after the arguments will be substituted?".
So in my opinion, it works as expected...
Because I guess the substitution of argv[0] (command) should be made exactly
the same manner as substitution of following arguments (argv[1]...argv[N]).
Trying to execute it twice:
% proc demo a {upvar 1 $a[proc upvar args {puts WOW}] b}
% demo a
% demo a
WOW
%
So corresponding to my question above, either the execution is correct at all, because we targeted here not yet changed "upvar", that will be modified after 1st execution only.
Or it is wrong, if resolving should take place implicit after substitution of the command arguments (I'm definitively against).
In my opinion this does not differ from the following logic (why it should be
different by the command resolving?):
% set x 1
1
% concat $x [incr x]
1 2
% concat $x [incr x]
2 3
IMHO rather the second example (your contrast example with "set u upvar; $u 1 $a[...") is wrong...
Please note this "undefined behavior" is very-very old - both variants behave this way at least since tcl-8.5.
But I assume that by tcl-8.4 the first variant ("upvar 1 $a[proc upvar ...") still printed "WOW" (just because another order of the "compilation" process).
Duplicated of http://core.tcl.tk/tcl/tktview/1812624 ?