Tcl Source Code

View Ticket
Login
Ticket UUID: 1274916
Title: upvar and qualified varNames
Type: Bug Created on: 2005-08-28 01:34:22
Submitter: msofer Assigned to: msofer
Subsystem: 07. Variables Severity:
Priority: 7 High Last modified: 2009-05-01 08:21:38
Status: Open Closed by:
Resolution: None Closed on:
Version: None
Description:
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).
User Comments:
msofer added on 2005-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.

msofer added on 2005-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)

msofer added on 2005-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.