deepCopy on Dictionary doesn't work.
| Project: | GNU Smalltalk |
| Component: | Base classes |
| Category: | bug |
| Priority: | normal |
| Assigned: | bonzinip |
| Status: | fixed |
Reproduce with:
st> (Dictionary from: {'a' -> 1}) deepCopy
Object: 1 error: did not understand #key
MessageNotUnderstood(Exception)>>signal
SmallInteger(Object)>>doesNotUnderstand: #key
Dictionary>>findElementIndex:
Dictionary(HashedCollection)>>addWhileGrowing:
[] in Dictionary(HashedCollection)>>deepCopy
[] in Dictionary>>do:
Dictionary(HashedCollection)>>do:
Dictionary>>do:
Dictionary(HashedCollection)>>deepCopy
UndefinedObject>>executeStatements
nil
Updates
| Assigned to: | Unassigned | » bonzinip |
| Status: | active | » reviewed |
| Attachment: | gst-dictionary-deepcopy.patch (736 bytes) |
Fixed with the attached patch. It copies both keys and values. Do you reckon it would be better to only copy values?
st> (Dictionary from: {'a' -> 1}) deepCopy keys anyOne == 'a'
false
st> (Dictionary from: {'a' -> 1}) deepCopy keys anyOne = 'a'
true
I would rather it copy keys, in the spirit of hardcore #deepCopy. One can always aDictionary collect: [:v | v copy]. Of course I am not elmex. :)
On the other hand one could say that for collections deepCopy *is* "aDictionary collect: [:v | v copy]"...
| Status: | reviewed | » fixed |
I committed patch-583, not copying keys after asking some people around. It turns out that copying keys is more likely to screw up users of IdentityDictionaries.
