deepCopy on Dictionary doesn't work.

Tagged:
Project:GNU Smalltalk
Component:Base classes
Category:bug
Priority:normal
Assigned:bonzinip
Status:fixed
Description

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

#1 submitted by Paolo Bonzini on Tue, 10/02/2007 - 16:27
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

#2 submitted by Stephen Compall on Wed, 10/03/2007 - 02:57

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. :)

#3 submitted by Paolo Bonzini on Wed, 10/03/2007 - 07:01

On the other hand one could say that for collections deepCopy *is* "aDictionary collect: [:v | v copy]"...

#4 submitted by Paolo Bonzini on Sat, 10/06/2007 - 08:20
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.

User login