
BUG: array traces and setting elements via upvar
With a trace on an array, setting an individual element is supposed to
invoke the trace procedure. This apparently doesn't happen when
an array element is upvar'd into another variable and then set.
An example:
proc Trace args {puts "** Trace $args"}
trace variable x w Trace
trace variable x(y) w Trace
# here you will see two identical calls to Trace, one for the array,
# and one for the element
set x(y) 1
puts "x(y)=$x(y)\n"
# again, two calls to Trace
upvar 0 x y
set y(y) 2
puts "x(y)=$x(y)\n"
# Here, only the second trace gets invoked
upvar 0 x(y) z
set z 3
puts "x(y)=$x(y)\n"
# Again, only the second trace gets invoked
proc PrefValueSet {_var _value} {
upvar #0 $_var var
set var $_value
}
PrefValueSet x(y) 4
puts "x(y)=$x(y)\n"
The output, for 7.5, 7.6p2, and 8.0a2, is:
** Trace x y w
** Trace x y w
x(y)=1
** Trace y y w
** Trace y y w
x(y)=2
** Trace z {} w
x(y)=3
** Trace var {} w
x(y)=4
The PrefValueSet example is from the Exmh Preferences code, which
I am (re)using in another application. I just merely wanted to
trace a preferences value to catch when it changes.
At the very least, I'd like to see a modification to the trace(n) and
the Tcl_TraceVar(3) man pages to reflect this behavior. Ideally,
I'd love to see array traces inherited by upvar'd array elements.
John
(p.s., I could swear I stumbed across this back a few months ago,
but I can find no record of me reporting this)