lassign to member variables in itcl methods
Closed / Fixed835020ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-11-03 13:29:51
Tcl version: 8.4.3
OS platform: Redhat 9, Solaris 2.8, SuSE 8, HP-UX 11
Problem behaviour: "lassign" does not store the value
of the member variable x in method "store" (see
sample code).
Running the sample code will print "0" on 8.4.3
and "2" on previous versions.
If the member variable x is referenced (e.g. with
"set a $x" then 8.4.3 will print the correct value.
Expected Behavior: as for previous tcl (tclx) versions
Concise Code Sample:
package require Tclx
package require Itcl
itcl::class T {
protected variable x 0
constructor {args} {
store
print
}
protected method store {} {
lassign 2 x
# set a $x
}
protected method print {} {
puts $x
}
}
T t
msoferplain2003-11-04 00:16:53
Logged In: YES user_id=148712 It looks like it could be a symptom of bug https://sourceforge.net/tracker/index.php?func=detail&aid=631741&group_id=10894&atid=110894 which is fixed in Tcl8.4.4 Does upgrading solve the issue?
pbiereicplain2003-11-04 02:25:53
Logged In: YES user_id=422762 Using Tcl 8.4.4 did not solve the issue.
msoferplain2003-11-04 05:11:12
Logged In: YES user_id=148712 TclX's lassign does a lookup by name, as Tcl_SetVar2Ex(interp, Tcl_GetStringFromObj(objv [idx], NULL), NULL, elemPtr, TCL_PARSE_PART1 | TCL_LEAVE_ERR_MSG) Apparently the problem is in how itcl varname resolver interact with the new tclVar code in this particular case; more research needed ...
eallaertplain2003-11-14 15:03:30
Logged In: YES user_id=204408 This problem appears also for TclX's "keylset" command, its "loop" command and any other command that is using a var-name as an argument. So the problem has unfortunately a much wider scope than originally reported.
msofer Ticket [835020ffff]: 1 change
[History diff]2003-11-20 23:50:09
msoferplain2003-11-20 23:50:10
Logged In: YES
user_id=148712
Eril Allaert reports in clt (verified with 8.4.4):
Try the following script, using tclsh:
package require Itcl
package require Tclx
itcl::class Test {
variable x 0
variable y 0
constructor {args} {
prep; # this should modify x and y ...
puts "$x [incr y]"; # ... which should be
noticeable here
}
method prep {} {
loop x 1 3 {puts "$x [incr y]"}
puts "local vars: >[info locals]<"
}
}
Test t
Expected output: 4 lines containing resp "1 1", "2 2",
"local vars: ><"
and "3 3". You get exactly that with Tcl 8.3.4, [incr Tcl]
3.2 and
TclX 8.3.5. But with Tcl 8.4.3, iTcl 3.3 and TclX 8.4 the
last line
is "0 3", and the one before "local vars: >x<". Same if Tcl
is upgraded
to Tcl 8.4.4.
Replacing TclX's loop command in the method prep by any of
the 17 other
TclX commands that require a variable name as argument
demonstrates the
same problem. The work-around to get this working again as
expected is
to have at least one standard Tcl command referring to this
variable
(e.g. "set x") anywhere within this prep method. This was
reported as
bug 835020 on SF, but initially mentioned only TclX's
"lassign" command.
dkfplain2003-11-21 01:09:44
Logged In: YES user_id=79902 Miguel's tracked this down to a clash between LOOKUP_FOR_UPVAR and TCL_PARSE_PART1
msoferplain2003-11-21 01:50:37
Logged In: YES user_id=148712 Bug found, fix committed to HEAD (8.5a0). It is possibly too late to get this fixed in 8.4.5, already frozen ... If you are compiling tcl from source: the fix is changing in generic/tclVar.c the flag value LOOKUP_FOR_UPVAR to 0x40000 (to avoid a collision with the deprecated TCL_PARSE_PART1, used throughout TclX).
msoferplain2003-11-21 01:52:07
Logged In: YES user_id=148712 Leaving open until tests for this bug are added to the testsuite
eallaertplain2003-11-21 19:32:02
Logged In: YES user_id=204408 I've tried the fix given by Miguel (changing LOOKUP_FOR_UPVAR in the file tclVar.c) on Tcl 8.4.3 and Tcl 8.4.4. I confirm that it fixes the problem as reported.
msoferplain2004-03-27 04:57:02
Logged In: YES user_id=148712 No pure-tcl test possible, I'm afraid. If anybody's got an idea ...
dkfplain2004-03-29 16:16:41
Logged In: YES user_id=79902 Exercising the API with the fault should be done via the tcltest binary even though the actual fault requires Itcl as well. 8.5 won't hit this with lassign, since that command has been completely reimplemented there.
msoferplain2004-03-30 09:39:16
Logged In: YES user_id=148712 Change of opinion: I do not think that a test for this particular flag collision's symptoms is necessary or interesting. Closing.
Log in (anonymous is fine) to add a comment.