[SR-15010] Settings Nil as Dictionary Value Produces Inconsistent Behavior #57340
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
duplicate
Resolution: Duplicates another issue
not a bug
Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error
regression
standard library
Area: Standard library umbrella
swift 3.0
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: