SR-3286 Dictionary element not removed in case of the value nil assignment
Issue Description:
According to Documentation:
If you assign nil as the value for the given key, the dictionary removes that key and its associated value.
In the following example, the key-value pair for the key "Aquamarine" is removed from the dictionary by assigning nil to the key-based subscript.
This works pretty well as long as I follow the example by using a nil literal to remove key-values, or by using a non-Optional Dictionary. If I have an Optional-valued Dictionary and use any other forms of nil, the removal is not guaranteed. It is confusing even, especially the short-hand case (.none) and fully-qualified case (X?.none) produce different results.
See the attached image for code sample.
P.S.: Also it may be debatable whether the nil-removal syntax should apply to Optional-valued Dictionaries at all. Because the point of using a Optional-valued Dictionary is to store Optionals. And an empty collection (no keys) vs. a collection of nils (keys present) are not the same thing.
The text was updated successfully, but these errors were encountered:
Attachment: Download
Environment
Xcode Version 12.5.1 (12E507)
macOS Version 11.5.1 (20G80)
Empty iOS Playground
Additional Detail from JIRA
md5: bf30fdd90bad10c8d136fc94ab01c86d
duplicates:
Issue Description:
According to Documentation:
This works pretty well as long as I follow the example by using a nil literal to remove key-values, or by using a non-Optional Dictionary. If I have an Optional-valued Dictionary and use any other forms of nil, the removal is not guaranteed. It is confusing even, especially the short-hand case (.none) and fully-qualified case (X?.none) produce different results.
See the attached image for code sample.
P.S.: Also it may be debatable whether the nil-removal syntax should apply to Optional-valued Dictionaries at all. Because the point of using a Optional-valued Dictionary is to store Optionals. And an empty collection (no keys) vs. a collection of nils (keys present) are not the same thing.
The text was updated successfully, but these errors were encountered: