info vars doesn't show object variables correctly
Closed / Fixed2712377fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 15 years ago
Descriptionplain2009-03-25 18:52:56
The following script behaves badly:
oo::class create test {
variable foo bar
method setvars {f b} {
set foo $f
set bar $b
}
method dump1 {} {
puts <1>
foreach v [info vars *] {
puts dump1:$v=[set $v]
}
}
method dump2 {} {
puts <2>
foreach v [info vars *] {
puts dump2:$v=[set $v]
}
puts foo=$foo
}
}
test create stuff
stuff setvars what ever
stuff dump1
stuff dump2
The output is
<1>
<2>
dump2:foo=what
foo=what
I would have expected that [info vars] returns both foo and bar in both dump methods.
cnassauplain2009-03-27 02:36:31
Here's another script that behaves strangely with respect to object variables:
oo::class create test {
variable foo
constructor {foo} {
set bar $foo
unset foo
my variable foo
set foo $bar
}
method dump {} {
puts foo=$foo
}
}
test create FOO BAR
FOO dump
Here "unset foo" fails with "can't unset "foo": no such variable". If that line is commented out the error becomes "variable "foo" already exists" from "my variable foo". I would have hoped that "FOO dump" produces "foo=BAR" in the end.
Again this report refers to CVS head (which identifies itself as 8.6b1.1 with TclOO 0.6.1).
dkfplain2009-04-17 17:02:44
The issue is that declared variables that aren't used aren't actually brought into the context. (That's how variable resolvers work.) Arguably the problem is that [info vars] doesn't do a nice job with resolvers in place, and not that TclOO "doesn't work".
dkf Ticket [2712377fff]: 1 change
[History diff]2009-11-27 13:44:45
dkfplain2012-04-10 00:06:01
allow_comments - 1 Fixed for 8.6; will not backport fix to 8.5 (really a Tcl introspection/resolver issue; can't fix from a package).
Log in (anonymous is fine) to add a comment.