Skip to content
Tcl Source Code View Ticket
Login

View Ticket

upvar links do not fire array read trace

Closed / Fixed572889ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 17 days ago
Descriptionplain2002-06-23 21:43:28
% set a(foo) 1
1
% trace variable a r {puts a ;#}
%  set a(foo)
a
1
% upvar 0 a(foo) baz
%  set baz
1

I would like to see the trace fire when
I read from baz.
Referenced by1
  • 09f2d9ae9ftcltest: on Tcl 9.0 and later, set the auto-configure read trace only on the Option array. Since TIP 634 it also fires when an option is read through the upvar-linked variables, so the per-variable traces, a workaround for [572889ffff], are only needed on Tcl 8.5 and 8.6. check-in2026-11-13 17:46:34
msoferplain2002-06-24 23:56:38
Logged In: YES 
user_id=148712

upvar.n dixit: "If otherVar refers to an element of an
array, then variable traces set for the entire array will
not be invoked when myVar is accessed (but traces on the
particular element will still be invoked). In particular, if
the array is env, then changes made to myVar will not be
passed to subprocesses correctly."

So, is this a bug or a FR? Does it need a TIP?
dgpplain2002-06-25 00:09:53
Logged In: YES 
user_id=80530

Thanks.  If this is to change, it would be a FR/TIP.
Don't feel strong enough about it to do that now,
but I'll shift this over the FR tracker in case
anyone else wants to pick it up.

Note to self: read *all* relevant man pages before
filing bugs...

Workaround seems to be to set traces on both
the source and target of the [upvar].  Works fine,
then, if annoying.
dgpplain2003-04-18 13:28:07
Logged In: YES 
user_id=80530


Joe, you were asking about this on the chat.
dkf Ticket [572889ffff]: 1 change [History diff]2003-06-26 17:35:45
dgp Ticket [572889ffff]: 1 change [History diff]2003-06-26 23:07:55
serhiy.storchakawiki2026-11-13 11:18:45

Implemented by TIP 634 in Tcl 9.0: traces on the whole array now fire when the array element is accessed through an upvar link, and the upvar manual page was updated accordingly.

dgpplain2026-11-13 16:15:31
Please note there is code in the tcltest package 
that is a workaround of the (mis)feature reported
in this ticket.  Someone with the time might examine
whether this workaround can be phased out now.
serhiy.storchakawiki2026-11-13 17:51:03

The workaround is the list of option variables in tcltest, which each get their own auto-configure read trace because a trace on the Option array did not fire through their upvar links. On Tcl 9.0 and later the trace on Option is enough, but tcltest still runs on Tcl 8.6 (and 8.5), where the workaround is still needed.

Proposed change in branch tcltest-array-trace-upvar: the per-variable traces are only set before Tcl 9.0.

jan.nijtmanswiki2026-11-15 14:14:38

Branch branch tcltest-array-trace-upvar is now merged to trunk, core-9-0-branch and core-8-6-branch. Good idea (without any ill-effects)

Log in (anonymous is fine) to add a comment.