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

Closed
swift-ci opened this issue Aug 2, 2021 · 1 comment
Closed
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

Comments

@swift-ci
Copy link
Collaborator

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

Environment

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

duplicates:

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

@swift-ci
Copy link
Collaborator Author

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
@AnthonyLatsis AnthonyLatsis added 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 swift 3.0 regression labels Dec 13, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants