Ok here is the reason
Name: Collections-md.18 Author: md Time: 7 August 2005, 3:26:12 pm UUID: 2d15dd50-ce8c-43d6-9f4e-4bd108c2af7d Ancestors: Collections-md.17
Change Set: WeakKeyDictionaryNilsFix Date: 5 December 2004 Author: Chris Muller
fixes this bug
Subject: [BUG] WeakKeyDictionary>>keysAndValuesDo: Author: Chris Muller Date Posted: 8 June 2004 Archive ID: 22746 Comments: The following code demonstrates that keysAndValuesDo: will evaluate nil keys that have been gc'd.
| d | d _ WeakIdentityKeyDictionary new at: 'hello' copy put: nil; yourself. Smalltalk garbageCollectMost. d keysAndValuesDo: [ : k : v | k ifNil: [ self halt ] ]
I consider this a bug because it contradicts the notion that nil cannot be a key in a Dictionary. Incidentally, keysDo: passes the test.
Dictionary>>at: key put: anObject "Set the value at key to be anObject. If key is not found, create a new entry for key and set is value to anObject. Answer anObject."
| index assoc | key ifNil: [ self error: 'Dictionaries cannot meaningfully key by nil.' ]. index _ self findElementOrNil: key. assoc _ array at: index. assoc ifNil: [self atNewIndex: index put: (Association key: key value: anObject)] ifNotNil: [assoc value: anObject]. ^ anObject
WeakKeyDictionary>>associationsDo: aBlock "Evaluate aBlock for each of the receiver's elements (key/value associations)."
super associationsDo: [ : eachAssoc | | eachKey | eachKey _ eachAssoc key. "reference to ensure no GC" eachKey ifNotNil: [ aBlock value: eachAssoc ] ]