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-9456] ObjC init marked NS_UNAVAILABLE is called from Swift when a 0-ary factory method is added #51919

Open
swift-ci opened this issue Dec 10, 2018 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9456
Radar rdar://problem/45304416
Original Reporter lucatorella (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ClangImporter
Assignee None
Priority Medium

md5: 36bc2e8ec7bacc7ccce7f21da3dc15a7

Issue Description:

If I have an Objective-C class where I have an init method marked as NS_UNAVAILABLE and a factory method with no arguments and if I try to call that factory method from Swift, then the init method is invoked instead.

Steps to Reproduce:
Create the following Objective-C class:

@interface SCNObject : NSObject
+ (instancetype)object;
- (instancetype)init NS_UNAVAILABLE;
@end

From Swift do:

_ = SCNObject()

It's easy to check with the debugger that the init method is called instead of the factory method.

If I remove the factory method, then the code won't compile and the proper error message is displayed: "'init()' is unavailable"

@hamishknight
Copy link
Collaborator

Interestingly enough, swapping the decls makes Swift call the factory method, e.g

@interface SCNObject : NSObject
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)object;
@end

@swift-ci
Copy link
Collaborator Author

Comment by Luca Torella (JIRA)

Wow, I didn't notice that 🙂

@belkadan
Copy link
Contributor

Hmph, I thought we fixed this. Thanks, Luca.

@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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants