Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[$obj varname] handling of linked variables

Closed / Fixed2da1cb0c808499bbd1d37e3a50291a26f8a46e14Created 9 years agoUpdated 2 years ago
Descriptionplain2018-05-08 13:57:08
% set o [oo::object new]
::oo::Obj11
% oo::objdefine $o export eval varname
% $o eval {namespace upvar :: nosuch test}
% $o varname test
::nosuch

Why not '::oo::Obj11::test' ?

% $o eval {namespace upvar :: tcl_platform(platform) foo}
% $o varname foo
%

Why not '::tcl_platform(platform)' ?

Or why not '::oo::Obj11::foo' ?

Is this behavior sensible? What should sensible behavior be and why?
Referenced by6
dgp Ticket [2da1cb0c80]: 4 changes [History diff]2018-05-08 13:58:22
dkfhtml2019-12-20 15:56:36

The first case works well enough (it is returning a handle to the correct variable) even if it is unexpected (due to following the rabbit hole of variable links).

The second case is a definite bug.

dkfmarkdown2024-05-23 13:49:41

The behaviour in the second case is due to:

    if (!varPtr || TclIsVarArrayElement(varPtr)) {
	return;
    }

in Tcl_GetVariableFullName() in tclVar.c. That is unexpected to me! (The function is only documented — in its header comment — to work with the results of Tcl_FindNamespaceVar(), but even so...)

dkfmarkdown2024-08-06 21:02:49

Fixed in 9.0, and not much prospect of backporting; it needs the new TclVarParentArray() macro (and supporting structure fields).

dkfplain2024-08-07 14:44:52
I've added a hack for 8.6 and 8.7 that returns the name of the variable within the object when it has no better option.
Log in (anonymous is fine) to add a comment.