Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2005-10-20
19:22 • Closed ticket [1333036fff]: lset misshandles sublists plus 3 other changes artifact: 2b9aa891ca user: msofer
18:00 • Ticket [1333036fff]: 4 changes artifact: ab305f03d6 user: msofer
10:05 • New ticket [1333036fff]. artifact: bd0a065aa8 user: msofer

lset misshandles sublists

Closed / Fixed1333036fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-10-20 10:05:31
(Bug reported on clt by neuronstorm at gmail dot com)

mig@ave:/home/CVS/tcl_SF_clean/unix$ cat /tmp/test
set a [list {1 b} {c d}]
set b $a
lset b 0 0 2  ;#change one subelement in the new list
puts "{$a}:{$b}:[expr {$b == $a}]"
mig@ave:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
{{2 b} {c d}}:{{2 b} {c d}}:1

Notes:
  1. The bug does not show at the console, nor within a
proc body
  
2. The bug does not show if the first line is replaced by
        set a {{1 b} {c d}}
but it still appears when it is
        set a [list [list 1 b] [list c d]]
msoferplain2005-10-20 18:00:23
Logged In: YES 
user_id=148712

(Thanks dkf) This duplicates the bug within a proc body by
avoiding a literal that shares the first sublist.

proc bar {} {
    set a [list [list 1 b] [list c d]]
    set b $a
    lset b 0 0 2  ;#change one subelement in the new list      
    puts stdout "a $a"
    puts stdout "b $b"
};bar

The problem is in the usage of the new List intrep that can
be shared: duplicating the List does not cause the elements
to be shared, the handling has not been done correctly in
TclLsetFlat.
msofer Closed ticket [1333036fff]. [History diff]2005-10-20 19:22:34
Log in (anonymous is fine) to add a comment.