Skip to content
Tcl Source Code History Of Ticket 1493a43044
Login

History Of Ticket 1493a43044

Artifacts Associated With Ticket 1493a43044

  1. Ticket change [463b7f8d02] (rid 146739) by beric on 2016-05-17 14:46:07:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      There is a problem using [namespace upvar] when - I guess - the target variable is also a variable of the class.
      
      Here is a contrived test which shows the problem:
      
      package require TclOO
      
      oo::class create Master {
          variable member1 member2
      
          constructor {} {
              set member1 "m1"
              set member2 "m2"
          }
          method getChild {} {
              Child new [self]
          }
      }
      
      oo::class create Child {
          variable member1
      
          constructor {m} {
              set ns [info object namespace $m]
              namespace upvar $ns \
                  member1 local_member1 \
                  member2 local_member2
      
              foreach {vref vloc} {
                  member1 local_member1
                  member2 local_member2
              } {
                  puts "$vref = [catch {set $vloc} err; set err]"
              }
          }
      }
      
      Master create m
      m getChild
      
      Outputs:
      
      member1 = can't read "local_member1": no such variable
      member2 = m2
      
      Looks like "local_member1" refers to Child member1 variable instead of Master member1 variable.
      
    5. foundin initialized to: "8.6.5"
    6. is_private initialized to: "0"
    7. login: "beric"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Severe"
    11. status initialized to: "Open"
    12. submitter initialized to: "beric"
    13. subsystem initialized to: "35. TclOO Package"
    14. title initialized to: "namespace upvar / TclOO problem"
    15. type initialized to: "Bug"
  2. Ticket change [70e2c0dca5] (rid 146741) by dgp on 2016-05-17 15:01:29:

    1. assignee changed to: "dkf"
    2. login: "dgp"
    3. mimetype: "text/plain"
  3. Ticket change [dc57338a40] (rid 146830) by beric on 2016-05-28 16:57:55:

    1. icomment:
      Tying to find the problem...
      Using [namespace upvar] through bytecode or via NamespaceUpvarObjCmd gives the same error.
      By the way, tcl::unsupported::disassemble has no way to get bytecode from constructor or destructor.
      
    2. login: "beric"
    3. mimetype: "text/plain"
  4. Ticket change [f47c83d0e3] (rid 146831) by beric on 2016-05-29 07:45:58:

    1. icomment:
      Debugging the non-bytecoded path, here is the stack of [namespace upvar]:
      
        ProcedureMethodCompiledVarConnect
        ProcedureMethodVarResolver
        TclLookupSimpleVar
        TclObjLookupVarEx
        NamespaceUpvarCmd
      
      ProcedureMethodCompiledVarConnect returns the Var bound to "member1" of Child class, while [namespace upvar] is asking for a specific context (Master namespace).
      
      Note that the bug is not present in 8.5.18 / TclOO 1.0.2.
      
    2. login: "beric"
    3. mimetype: "text/plain"
  5. Ticket change [f5722099d7] (rid 146832) by beric on 2016-05-29 09:30:17:

    1. icomment:
      Similar to [631741]? Should AVOID_RESOLVERS flag be used?
      
    2. login: "beric"
    3. mimetype: "text/plain"
  6. Ticket change [222d9cf09e] (rid 147442) by dkf on 2016-07-03 11:50:51:

    1. icomment:
      <blockquote><i>By the way, <code>tcl::unsupported::disassemble</code> has no way to get bytecode from constructor or destructor.</i></blockquote>
      Hmm, that's correct. Missed it.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. priority changed to: "7 High"
  7. Ticket change [fd2a1176ea] (rid 147452) by dkf on 2016-07-04 08:20:44:

    1. icomment:
      The disassembler's now been enhanced on the 8.6 branch; it'll hit <tt>trunk</tt> and <tt>novem</tt> in due course.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  8. Ticket change [d95edc63b6] (rid 147464) by dkf on 2016-07-04 09:23:48:

    1. icomment:
      I can reproduce the problem, but don't really understand what is failing.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  9. Ticket change [e567ef7f18] (rid 147465) by dkf on 2016-07-04 09:28:31:

    1. icomment:
      And disassembling the constructor really doesn't help very much.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  10. Ticket change [0519bf3669] (rid 147466) by aspect on 2016-07-04 15:19:31:

    1. icomment:
      Just noting that it's hard to reproduce with a variation.  Moving the constructor body into a method has no effect, but:
      
      Changing the source or destination to be a pure namespace (rather than an object) - no error.
      
      Moving [variable member1] into the constructor, with or without [my] - no error.
      
      Replacing [namespace upvar] with [upvar #0] - no error.
      
      
      Minimal test case seems to be:
      
      test .. .. -body {
        oo::class create M {
          variable v
          constructor {} {
            set v Mval
          }
        }
      
        oo::class create C {
          variable v
          method x {ns} {
            set v Cval
            namespace upvar $ns v l
            return $l
          }
        }
      
        M create m
        C create c
        c x [info object namespace m]
      } -cleanup {
        M destroy
        C destroy
      } -result Mval
      
    2. login: "aspect"
    3. mimetype: "text/plain"
  11. Ticket change [8812d40008] (rid 147469) by aspect on 2016-07-04 22:59:17:

    1. icomment:
      Also, <a href="http://core.tcl.tk/tcl/artifact/4934be5292011064?ln=4538-4543">yuck</a>.  Just eyeballing that code without knowing much about it, the proc-local variable is what I expect it to look up.
      
    2. login: "aspect"
    3. mimetype: "text/html"
  12. Ticket change [9c407e65ec] (rid 147497) by dkf on 2016-07-05 22:13:30:

    1. icomment:
      The code is quite possibly imperfect. I've added a test case on the [<a href="http://core.tcl.tk/tcl/timeline?r=bug-1493a43044">bug-1493a43044</a>] branch. The test currently fails, so I'm on a branch for now.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  13. Ticket change [5c36277369] (rid 147581) by dkf on 2016-07-07 10:14:57:

    1. icomment:
      Thank you for the hint about <code>AVOID_RESOLVERS</code>. It does appear to be exactly the missing ingredient precisely because it was previously internal to <i>tclVar.c</i> while <code>namespace upvar</code> is implemented in <i>tclNamesp.c</i> and <i>tclExecute.c</i>. Exposing (as the imaginatively named <code>TCL_AVOID_RESOLVERS</code> in <i>tclInt.h</i>) seems reasonable, and doesn't break any existing tests (while fixing this).
      <p>
      My main worry now is that this will cause problems with Itcl. Need to check before committing the fix back to a main branch…
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  14. Ticket change [941152f68f] (rid 147733) by dkf on 2016-07-09 13:24:57:

    1. icomment:
      I've been thinking about this a bit more. When someone uses <code>namespace upvar</code>, they really do mean that they want the variable in that namespace, not to perform a name lookup according to that namespace's rules or the current namespace's rules either. As such, preventing the use of resolvers is exactly the right approach <i>even in [incr Tcl] classes</i>. If they wanted resolution, they wouldn't use <code>namespace upvar</code> (which isn't really itcl style anyway).
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  15. Ticket change [47ca2a414a] (rid 147736) by dkf on 2016-07-09 13:27:41:

    1. closedate changed to: "2457579.06089265"
    2. closer changed to: "dkf"
    3. icomment:
      Fixed in 8.6 branch. Merge to trunk will happen at next inter-branch sync.
      
    4. login: "dkf"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"