Skip to content
Tcl Source Code History Of Ticket 477e96c250
Login

History Of Ticket 477e96c250

Artifacts Associated With Ticket 477e96c250

  1. Ticket change [25f325df02] (rid 254192) by anonymous on 2026-06-04 02:23:15:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      In the following example, the classvariable m_columns statement inside of classmethod setit creates a variable that is unusable in the ordinary way in a new namespace in the ::oo space rather than link to the class-wide variable as one would expect. This produces a bug which is hard to diagnose.
      
      Note that if one does the same thing in the initialize section, an error is thrown:  "self may only be called from inside a method". That error seems to be based on the imlementation of initialize and could probably be more helpful and direct with different wording, but at least it doesn't silently create an unreachable variable.
      
      The workaround is to use variable instead of classvariable inside the classmethod. But this is likely to be forgotten since it doesn't seem consistent.
      
       oo::class create test1 {
          initialize {
              variable m_columns [dict create initial {value1 value2 value3}]
          }
          
          classmethod setit {} {
              classvariable m_columns
              dict set m_columns foo {garp parp snarp}
              puts [format {in setit: self=%s m_columns=%s} [self] $m_columns]
          }
          
          constructor {} {
              classvariable m_columns
              puts [format {in constructor: self=%s m_columns=%s} [self] $m_columns]
          }
      
          method showit {} {
              classvariable m_columns
              puts [format {in showit: self=%s m_columns=%s} [self] $m_columns]
          }
      }
      
      
      % test1 setit
      in setit: self=::test1 m_columns=foo {garp parp snarp}
       % info object namespace ::test1
      ::oo::Obj106
       % set r [test1 new]
      in constructor: self=::oo::Obj108 m_columns=initial {value1 value2 value3}
      ::oo::Obj108
       % $r showit
      in showit: self=::oo::Obj108 m_columns=initial {value1 value2 value3}
       % 
       % info vars ::oo::Obj106::*
      ::oo::Obj106::m_columns
       % info vars ::oo::Obj107::*
      ::oo::Obj107::m_columns
       % info vars ::oo::Obj108::*
       % 
       % set ::oo::Obj106::m_columns
      initial {value1 value2 value3}
       % set ::oo::Obj107::m_columns
      foo {garp parp snarp}
       %
      
    5. foundin initialized to: "9.1a0"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "anonymous"
    13. subsystem initialized to: "35. TclOO Package"
    14. title initialized to:
      classvariable inside classmethod creates unusable variable
      
    15. type initialized to: "Bug"