Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2000-10-26
08:29 • Closed ticket [218782ffff]: trace variable / upvar problem plus 4 other chan... artifact: 6bfeb875f7 user: welch
01:05 • New ticket [218782ffff]. artifact: d1ac289e57 user: nobody

trace variable / upvar problem

Closed / Fixed218782ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:05:17
OriginalBugID: 2110 Bug
Version: 8.1
SubmitDate: '1999-05-20'
LastModified: '2000-01-20'
Severity: LOW
Status: Released
Submitter: pat
ChangedBy: ericm
OS: All
FixedDate: '2000-01-20'
FixedInVersion: 8.3
ClosedDate: '2000-01-20'


Name:
Greg Orchard

ReproducibleScript:
proc update {name index op} {
        puts "name $name index $index"
    }
    
    proc getUpdate {inVar} {
        upvar $inVar localVar
        set localVar 100
    }
    
    trace variable somevar w update
    getUpdate somevar(1)

ObservedBehavior:
The output from the above is:
    
    name localVar index

DesiredBehavior:
I would expect to see:
    
    name somevar index 1
    
    since "somevar" is the one variable being traced.



This is actually the designed behaviour.  While it may seem obivously incorrect, consider the case in which there are two levels of upvar, and multiple traces:

proc update {name index op} {
puts "name $name index $index"
}

proc getUpdate {inVar} {
upvar $inVar localVar
trace variable localVar w update
getUpdate2 localVar
}

proc getUpdate2 {inVar} {
upvar $inVar localVar2
set localVar2 100
}

trace variable somevar w update
getUpdate somevar

Now it is not so clear what the behaviour should be.  Which trace should fire?  what name should it be given?  If there are many levels of indirection, it could be costly to try and determine which trace should be fired with which variable name.  And because all of the variable names actually refer to the same object, it is least confusing to fire all of the traces with the name used to trigger the trace.

- eric

-- 01/20/2000 ericm
welch Closed ticket [218782ffff]. [History diff]2000-10-26 08:29:14
Log in (anonymous is fine) to add a comment.