Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-09-28
04:52 • Ticket [3075907fff] info vars implementation and man page do not agree sta... artifact: e54694db76 user: jenglish
2010-09-27
23:49 • Closed ticket [3075907fff]. artifact: 55985dc708 user: msofer
23:29 • Pending ticket [3075907fff]. artifact: ebd9a6fa00 user: hobbs
23:29 • Ticket [3075907fff]: 5 changes artifact: e4f2586e5d user: hobbs
22:43 • Ticket [3075907fff]: 4 changes artifact: ccb3088636 user: msofer
16:33 • Ticket [3075907fff]: 5 changes artifact: 7c1591ec2b user: msofer
16:15 • Ticket [3075907fff]: 4 changes artifact: 524bd0c956 user: msofer
2010-09-26
12:53 • New ticket [3075907fff]. artifact: f41882335a user: msofer

[info vars] implementation and man page do not agree

Closed / Invalid3075907fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-09-26 12:53:43
The man page states for [info vars]:
"Note that a currently-visible variable may not yet “exist” if it has not been set (e.g. a variable declared but not set by variable)."

However

% unset -nocomplain x y
% proc a {} {variable x; upvar y z; info vars}
% a
x z

This behaviour is present at least in 8.4.19, 8.5.9 and 8.6 (did not check earlier Tcl versions). That is, it may well be a "documentation bug" by now.
msoferplain2010-09-27 16:15:05
Note that the current behaviour is difficult to implement correctly in the presence of variable resolvers, as used eg by TclOO: see #3075155
msoferplain2010-09-27 16:33:38
IMO the present behaviour is NOT correct, we should revert to the documented behaviour: the present behaviour is inconsistent in the treatment of uninitialised variables in the presence of var resolvers.

To be explicit, the consistent choices are IMO are:

1. never report an unitialised variable, be it a link or not
2. report all resolved variables - impractical, difficult and expensive
msoferplain2010-09-27 22:43:30
There seem to be no tests whatsoever for what happens with declared-but-undefined variables: [global], [variable], [upvar], [namespace upvar], OO's [variable]. 

The interaction with varname resolvers is impossible to bring up to the current behaviour without extending the api: we should extend Tcl_ResolverInfo to contain a listProc to be used by [info vars]. This new function would list all variable names that are able to be resolved in the current context.
hobbsplain2010-09-27 23:29:09
This has been the behavior in Tcl since at least Tcl 8, and I believe before.  I had to deal with it in tkcon.

I believe it also matches the docs.  As stated in the docs, 'info vars' will return these "visible-but-not-exists", and you have to test against 'info exists' for true existence in the "is set" sense.
hobbs Pending ticket [3075907fff]. [History diff]2010-09-27 23:29:53
msoferplain2010-09-27 23:49:52
allow_comments - 1

OMG, I now believe I misread the docs - this is no bug. As you were ...
jenglishplain2010-09-28 04:52:24
FWIW and IMNSHO: the semantics of [info vars] and [info locals] have always been ill-defined at best; and the in-practice semiotics seems to be "they're sometimes useful for debugging/introspection".  Any test that uses them should be considered white-box.
Log in (anonymous is fine) to add a comment.