Tcl Source Code

View Ticket
Login
Ticket UUID: 2712377
Title: info vars doesn't show object variables correctly
Type: Bug Created on: 2009-03-25 18:52:56
Submitter: cnassau Assigned to: dkf
Subsystem: 07. Variables Severity:
Priority: 6 Last modified: 2012-04-10 00:06:01
Status: Closed Closed by: dkf
Resolution: Fixed Closed on: 2012-04-09 17:06:01
Version: obsolete: 8.6b1.1
Description:
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.
User Comments:
cnassau added on 2009-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).

dkf added on 2009-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 added on 2012-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).