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-2742] Using NS_STRING_ENUM, the init(rawValue:) documentation doesn’t match the code #45346

Open
SlaunchaMan opened this issue Sep 23, 2016 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@SlaunchaMan
Copy link
Contributor

Previous ID SR-2742
Radar None
Original Reporter @SlaunchaMan
Type Bug

Attachment: Download

Environment

Xcode Version 8.0 (8A218a)
Swift 3
macOS Sierra 10.12 (16A323)

Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels Bug
Assignee None
Priority Medium

md5: 9aa3031d55083c164e1a46097c2e3776

Issue Description:

When using NS_STRING_ENUM, I have a type that is defined as follows:

typedef NSString * JKExampleKey NS_STRING_ENUM;
extern JKExampleKey const JKExampleKeyAlpha;
extern JKExampleKey const JKExampleKeyBeta;
extern JKExampleKey const JKExampleKeyGamma;

Using this type in Swift, I want to attempt to make a key out of a string:

func doSomething(withString string: String) {
    if let key = JKExampleKey(rawValue: string) {
        // Do something with the key
    }
}

Unfortunately, this fails with the error “Initializer for conditional binding must have Optional type, not 'JKExampleKey'”.

The init(rawValue: ) method of JKExampleKey is not failable—it does not return an Optional. However, the documentation that appears when I option-click the initializer reads differently:

@belkadan
Copy link
Contributor

Hm. On the one hand, it doesn't make sense to try to produce custom documentation for every synthesized method. On the other hand, the inherited documentation from the protocol doesn't make sense with the modified signature. @akyrtzi, @natecook1000, @dabrahams, what do you think?

@dabrahams
Copy link
Collaborator

I think we at least need to do it when the signature of an override differs in optionality from that of its base

@belkadan
Copy link
Contributor

Need to do what? We don't know anything about the enum, so synthesis would just have some dummy text like "Wraps the raw string value in the $0 type".

@dabrahams
Copy link
Collaborator

Need to "produce custom documentation"

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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.
Projects
None yet
Development

No branches or pull requests

3 participants