Artifacts Associated With Ticket 1493a4304444fcfb
Ticket change [463b7f8d02] (rid 146739) by beric on 2016-05-17 14:46:07:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- 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. - foundin initialized to: "8.6.5"
- is_private initialized to: "0"
- login: "beric"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "beric"
- subsystem initialized to: "35. TclOO Package"
- title initialized to: "namespace upvar / TclOO problem"
- type initialized to: "Bug"
Ticket change [70e2c0dca5] (rid 146741) by dgp on 2016-05-17 15:01:29:
- assignee changed to: "dkf"
- login: "dgp"
- mimetype: "text/plain"
Ticket change [dc57338a40] (rid 146830) by beric on 2016-05-28 16:57:55:
- 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.
- login: "beric"
- mimetype: "text/plain"
- icomment:
Ticket change [f47c83d0e3] (rid 146831) by beric on 2016-05-29 07:45:58:
- 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.
- login: "beric"
- mimetype: "text/plain"
- icomment:
Ticket change [f5722099d7] (rid 146832) by beric on 2016-05-29 09:30:17:
- icomment:
Similar to [631741]? Should AVOID_RESOLVERS flag be used?
- login: "beric"
- mimetype: "text/plain"
- icomment:
Ticket change [222d9cf09e] (rid 147442) by dkf on 2016-07-03 11:50:51:
- 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.
- login: "dkf"
- mimetype: "text/html"
- priority changed to: "7 High"
- icomment:
Ticket change [fd2a1176ea] (rid 147452) by dkf on 2016-07-04 08:20:44:
- 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.
- login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [d95edc63b6] (rid 147464) by dkf on 2016-07-04 09:23:48:
- icomment:
I can reproduce the problem, but don't really understand what is failing.
- login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [e567ef7f18] (rid 147465) by dkf on 2016-07-04 09:28:31:
- icomment:
And disassembling the constructor really doesn't help very much.
- login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [0519bf3669] (rid 147466) by aspect on 2016-07-04 15:19:31:
- 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 - login: "aspect"
- mimetype: "text/plain"
- icomment:
Ticket change [8812d40008] (rid 147469) by aspect on 2016-07-04 22:59:17:
- 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.
- login: "aspect"
- mimetype: "text/html"
- icomment:
Ticket change [9c407e65ec] (rid 147497) by dkf on 2016-07-05 22:13:30:
- 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.
- login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [5c36277369] (rid 147581) by dkf on 2016-07-07 10:14:57:
- 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…
- login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [941152f68f] (rid 147733) by dkf on 2016-07-09 13:24:57:
- 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).
- login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [47ca2a414a] (rid 147736) by dkf on 2016-07-09 13:27:41:
- closedate changed to: "2457579.06089265"
- closer changed to: "dkf"
- icomment:
Fixed in 8.6 branch. Merge to trunk will happen at next inter-branch sync.
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"