Tcl Source Code

View Ticket
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.
Ticket UUID: 219372
Title: Cannot set env array element via upvar #0
Type: Bug Version: obsolete: 8.3.1
Submitter: nobody Created on: 2000-10-26 05:11:46
Subsystem: 08. Environment Variables Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Open Last Modified: 2006-03-10 23:35:17
Resolution: None Closed By:
    Closed on:
Description:
OriginalBugID: 5991 Bug
Version: 8.3.1
SubmitDate: '2000-07-06'
LastModified: '2000-10-25'
Severity: MED
Status: UnAssn
Submitter: techsupp
OS: Windows NT
OSVersion: Windows NT 4.0 Build 1381 SP6
Machine: x86 Family 6 Model 5 Stepping 2 AT/AT Compatible
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name:
David M. Eason

Extensions:
None

CustomShell:
No changes

Comments:
One workaround is to use "global env" and explicitly reference the
    desired element each time it is set.

ReproducibleScript:
array set inv {1 one 2 two}
array set env {SSDIR c:/}

proc setinv {n v} {upvar #0 inv($n) x; set x $v}
proc setenv {n v} {upvar #0 env($n) x; set x $v}

puts [setinv 1 won] ;#Displays "won"
puts $inv(1) ;#Also displays "won" (this is correct)

puts [setenv SSDIR d:/] ;#Display "d:/"
puts $env(SSDIR) ;#Displays "c:/" (this is unexpected)

ObservedBehavior:
It appears that elements of the "env" array cannot be set using the upvar mechanism, but elements of other arrays can.  The documentation states that upvar can be applied to array elements.  Nothing special about "env" is noted on the help pages for array, tclvars, or upvar.

DesiredBehavior:
I expect to see the new value of the env array element in subsequent references.
User Comments: dgp added on 2006-03-10 23:35:17:
Logged In: YES 
user_id=80530

status?

dgp added on 2001-09-28 02:15:18:
Logged In: YES 
user_id=80530

This bug breaks the Unix URL following of the tkchat client
program.  Would be nice to get it assigned and fixed.  It's
been broken since Tcl 8.1.

Here's a quick demo script:

proc bar varName {upvar 1 $varName result; set result value}
proc foo {} {global env; bar env(TEST); set env(TEST)}
foo

Andreas tells me the submitter is David M. Eason,
<[email protected]>.

andreas_kupries added on 2001-09-28 02:11:13:
Logged In: YES 
user_id=75003

David M. Eason = <[email protected]>

dkf added on 2001-02-07 22:48:58:
This is due to an interaction between an environment variable mechanism strangeness (the env array is *different*) and the array-variable mechanism (which currently means that if you upvar a single element of an array, no global traces on that array get called when you get/set that variable) that is unfortunate.  A work-around is to upvar the whole array and set an element of that, which works.

dkf added on 2000-11-13 20:41:14:
This is an unfortunate side effect of the way that variables in arrays are implemented (the contained variables do not know that they are contained within an array) and fixing it will require adding a field to struct Var to refer to the containing variable.  An alternative would be to change the documentation for upvar, but that would be merely enshrining a misfeature in the cloak of "standard documented behaviour".  :^(