Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Bytecode machinery to handle compile epoch bumps is not right.

Closed / Duplicate9a2bc209faf87b2f156d1971447f59e294184f9eCreated 9 years agoUpdated 9 years ago
Descriptionplain2017-06-06 16:37:46
% 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
%
sebreswiki2017-06-06 17:24:36

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

sebresplain2017-06-06 17:49:02
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).
emilianoplain2017-06-07 02:38:47
Duplicated of http://core.tcl.tk/tcl/tktview/1812624 ?
dgp Closed ticket [9a2bc209fa]. [History diff]2017-06-08 11:26:27
Log in (anonymous is fine) to add a comment.