Dictionaries broken in 3.9a

Chris Muller chris at funkyobjects.org
Tue Sep 20 16:45:27 UTC 2005


> Well, I was quite disturbed to find out that:
> 1. #associationsDo: does not process all of the associations in the
> dictionary.
> That's what the message asks for, not all non-nil-key associations.

The whole premise of my question was asking whether nil keys should be allowed
in WeakKeyDictionary's.  If not, then "all" would imply "all non-nil" keys.

Its a worthy question because special conditions arise out of allowing nil
keys.  For example, since when does any Dictionary report multiple entries at
the same key when using keysAndValuesDo: and then report "key not found" when
using at: for that key?

|d|
d := WeakKeyDictionary new
	at: 'hello' copy put: 'abc' ;
	at: 'world' copy put: 'def' ;
	yourself.
Smalltalk garbageCollect.
d keysAndValuesDo: [ : k : v | Transcript cr; show: k printString, v
printString ]
d at: nil

I think this clearly demonstrates that nil is not just another key; it's
special.  Since my work in other Smalltalks did not allow nil keys in
Dictionary's, I had assumed it was a bug.  Since I was wrong, I apologize.  I
now ask for your help and clarification.

> 2. Finalization was completely broken by this change.

Really?  That is disturbing.

> Funny, I would have guessed that a lack of any finalization would affect
> the functioning of something like Magma....

Not sure since I don't ever override #finalize.  No finalization issues have
been reported to me regarding the use of Magma.  However, it has been noticed
WeakKeyDictionary's grow tremendously before Squeak clears out the nil keys,
encouraging the user to explicitly #finalizeValues themselves occasionally.. 
Is this due to finalization being broken?

Regards,
  Chris



More information about the Squeak-dev mailing list