Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-05-01
08:21 • Ticket [1274916fff] upvar and qualified varNames status still Open with 1 ot... artifact: 43233eb3d4 user: msofer
2005-08-28
19:47 • Ticket [1274916fff]: 4 changes artifact: 1f926d9010 user: msofer
19:37 • Ticket [1274916fff]: 4 changes artifact: a3411fa5a3 user: msofer
08:51 • Ticket [1274916fff]: 4 changes artifact: 15d65f22cb user: msofer
01:34 • New ticket [1274916fff]. artifact: 071f25f6b1 user: msofer

upvar and qualified varNames

Open1274916fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 18 years ago
Descriptionplain2005-08-28 01:34:22
The behaviour of
  upvar otherVar myVar
is wrong when myVar is a qualified name, as it does not
follow Tcl's (insane?) variable resolution rules: it
skips the global lookup upon failure of the local one.
Witness:

% set x 1
1
% namespace eval a {upvar x b::x}
can't create "b::x": parent namespace doesn't exist
% namespace eval b {}
% namespace eval a {upvar x b::x}
can't create "b::x": parent namespace doesn't exist
% namespace eval b {variable x 2}
% namespace eval a {upvar x b::x}
can't create "b::x": parent namespace doesn't exist
% namespace eval a {set b::x}
2

This worked as expected in Tcl8.3.4, and is broken as
described above in 8.4.7 and HEAD. Breakage was
probably introduced at some point in the 8.4 line
(LOOKUP_FOR_UPVAR).
msoferplain2005-08-28 08:51:53
Logged In: YES 
user_id=148712

Note that this behaviour was introduced as a fix for Bug
#696893.

Avoiding the global lookup appears not to have been a
correct reconstruction of Tcl8.3's lookup rules.
msoferplain2005-08-28 19:37:39
Logged In: YES 
user_id=148712

The problem is that [upvar] has different rules for creative
writing in the not-fully-qualified case. In the example above
  namespace eval a {upvar x b::x}
the new variable should refer (in order) to:

  (1) ::a::b::x if the namespace ::a::b exists
  (2) ::b::x     if the namespace ::b     exists

Note that this refers to the existence of namespaces; the
usual resolution rules refer to the existence of the
variables themselves, ie for [namespace eval a {set b::x 1}]
the reference is to:

  (1) ::a::b::x if the variable ::a::b::x exists
  (2) ::b::x     if the variable ::b::x     exists
  (3) ::a::b::x otherwise (even if ::b exists but ::a::b
does not)
msoferplain2005-08-28 19:47:17
Logged In: YES 
user_id=148712

The question now is if this behaviour in 8.3 is intended, or
just an implementation side effect. Ths docs do not even
mention the possibility of creating anything but a
proc-local variable via upvar.
msofer Ticket [1274916fff]: 1 change [History diff]2009-05-01 08:21:38
Log in (anonymous is fine) to add a comment.