Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-15010] Settings Nil as Dictionary Value Produces Inconsistent Behavior #57340

swift-ci opened this issue Aug 2, 2021 · 1 comment


Copy link

@swift-ci swift-ci commented Aug 2, 2021

Previous ID SR-15010
Radar None
Original Reporter VaslD (JIRA User)
Type Bug
Status Closed
Resolution Duplicate

Attachment: Download


Xcode Version 12.5.1 (12E507)

macOS Version 11.5.1 (20G80)

Empty iOS Playground

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: bf30fdd90bad10c8d136fc94ab01c86d


  • 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.

Copy link
Collaborator Author

@swift-ci swift-ci commented Aug 2, 2021

Comment by Yi Ding (JIRA)

Found answered issue after tweaking my search, duh...

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant