|
Dictionary withAll: is implemented in terms of Dictionary>>addAll: which contains a special case to deal with aDictionary addAll: bDictionary. Unfortunately this adaptor produces unexpected results for aDictionary addAll: aSequenceOfAssociations. Pharo's 2003 method by raok reads addAll: aKeyedCollection aKeyedCollection == self ifFalse: [ aKeyedCollection keysAndValuesDo: [:key :value | self at: key put: value]]. ^aKeyedCollection Andreas Raab changed Squeak's version in 2010 to read addAll: aCollection "Include all the associations of aCollection as the receiver's elements. Answer aCollection. Any collection containing associations can be used as argument."
aCollection == self ifFalse: [ aCollection associationsDo: [:assoc| self add: assoc]. ]. ^aCollection Hence in Pharo Dictionary withAll: { 2 -> 3 } => a Dictionary (1->2->3 ) but in Squeak Dictionary withAll: { 2 -> 3 } => a Dictionary (2->3 ) The latter feels much more natural and expected. This is born out by looking for all users of Dictionary binding and #withAll:. No one uses Dictionary class>>withAll:, I expect because the behavior is so non-intuitive.
Peter Uhnak notes that this is related to 'abc' collect: [ :each | each -> each asciiValue ] as: Dictionary "a Dictionary(1->$a->97 2->$b->98 3->$c->99 )" But the fix herein does not address that.
|
|
|
Priority: 5 – Fix If Time
|
|
Status: Work Needed
|
|
Assigned to: Everyone
|
|
Milestone: Later
|
Go to Case
|
|