Skip to content

Fixes example snippet in OptionSet.swift #33846

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

Closed
wants to merge 1 commit into from

Conversation

valeriyvan
Copy link
Contributor

Fixes example snippet in OptionSet.swift

@xwu
Copy link
Collaborator

xwu commented Sep 7, 2020

Well found, but what you've discovered isn't good! I wonder if it's a known bug. The result should be as indicated in the documentation currently, and I can't clearly see why it's not. For kicks, I rewrote the function verbatim:

extension OptionSet where Element == Self {
  mutating func __remove(_ member: Element) -> Element? {
    let intersectionElements = intersection(member)
    guard !intersectionElements.isEmpty else { return nil }
    subtract(member)
    return intersectionElements
  }
}

var options: ShippingOptions = [.secondDay]
options.remove(.express) // nil

options: ShippingOptions = [.secondDay]
options.__remove(.express) // ShippingOptions(rawValue: 2)

@xwu
Copy link
Collaborator

xwu commented Sep 7, 2020

cc @natecook1000 @airspeedswift

@natecook1000
Copy link
Member

It looks like that behavior was fixed in 5.3 (#28378), so whether or not you're getting that fix depends on which version of the stdlib your code is hitting.

@xwu
Copy link
Collaborator

xwu commented Sep 8, 2020

Phew, I was worried that I was seeing some dynamic dispatch shenanigans here.

@valeriyvan valeriyvan deleted the OptionSet branch January 26, 2023 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants