init marked as NS_UNAVAILABLE is called from Swift when a factory method is added

Originator:luca
Number:rdar://46592500 Date Originated:2018/12/10
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:Yes
 
Summary:
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"

Expected Results:
The factory method should be invoked.

Actual Results:
The init method is invoked.

Version/Build:
Swift 4.2, Xcode 10.1

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!