Strict Symbol Comparison in HashedCollections
In this case the issue is not with the receiver's equality (e.g. Dictionary>>#=
), but in the key lookup, i.e. in standard Pharo the following snippet answers a dictionary with 1 entry. With strict symbol comparison the dictionary will have two entries:
Dictionary new at: #a put: 1; at: 'a' put: 2; yourself
There are three broad approaches to dealing with this scenario:
Change the class of the collection
Replacing the instance creation of, e.g. Dictionary
with GtStringContentDictionary
means that no further modifications are required since the string comparison is used even when strict symbol comparisons are enabled.
Ensure the key has the correct class when accessing
This can be done by converting the key just prior to use, e.g. aString asSymbol
,
Ensure the key has the correct class when loading / initialising
This frequently occurs when loading data from json files, resulting in a dictionary having String keys when they would normally be expected to have Symbols.