Mantis - Squeak
Viewing Issue Advanced Details
7258 Collections minor always 12-30-08 22:50 04-18-10 22:04
nicolas cellier  
nicolas cellier  
normal  
closed 3.10  
fixed  
none    
none trunk  
0007258: Dictionary asSet is wrong
Following http://lists.squeakfoundation.org/pipermail/squeak-dev/2007-June/117894.html [^]
that recently came up through http://lists.gforge.inria.fr/pipermail/pharo-project/2008-December/004305.html [^]
I have prepared a little test:

| aDictionary aSet |
aDictionary := Dictionary new.
aSet := aDictionary asSet.
assoc0 := #first -> 0.
assoc1 := #first -> 1.
aSet add: assoc0; add: assoc1.
self
    assert: (assoc0 ~= assoc1) ==> (aSet size > 1)
    description: '
        When adding two different elements,
        the set size should be greater than one'
Guess what is (aSet class) ?

No, a Dictionary is not a Set of associations, at least since Assocation>>#= has been changed to also test the value.

It used to be a Set of Associations in st80 when only the association key was compared...
 M7258-Dictionary-asSet-Test-nice.1.cs [^] (938 bytes) 10-06-09 12:24
 M7258-Dictionary-asSet-Patch-nice.1.cs [^] (1,635 bytes) 10-06-09 12:25

Notes
(0012885)
nicolas cellier   
12-30-08 22:57   
"Hem, I posted my test too fast...
 it results in assoc0 = assoc1, because #add: will modify assoc0 in place...
 though aSet size = 1, the assertion did not fail..."

| aDictionary aSet assoc0 assoc1 |
aDictionary := Dictionary new.
aSet := aDictionary asSet.
assoc0 := #first -> 0.
assoc1 := #first -> 1.
aSet add: assoc0 copy; add: assoc1.
self
    assert: (assoc0 copy ~= assoc1) ==> (aSet size > 1)
    description: '
        When adding two different elements,
        the set size should be greater than one'

(0013359)
nicolas cellier   
10-06-09 12:26   
"fix begin"
Installer mantis bug: 7258 fix:'M7258-Dictionary-asSet-Patch-nice.1.cs'.
"fix test"
Installer mantis bug: 7258 fix:'M7258-Dictionary-asSet-Test-nice.1.cs'.
"fix end"
(0013360)
nicolas cellier   
10-06-09 12:31   
Fixed in http://source.squeak.org/trunk/Collections-nice.162.mcz [^]
and http://source.squeak.org/trunk/CollectionsTests-nice.102.mcz [^]