You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-6993 Swift imports @optional ObjC methods from superclass protocol as if implemented
Issue Description:
If you have
a Swift subclass of an ObjC class
where the ObjC class conforms to an ObjC protocol,
the protocol declares an init method marked as unavailable,
the ObjC class (correctly) does not implement the unavailable init method,
and the Swift subclass declares its own init method
... the Swift compiler will incorrectly require that the unavailable init method be implemented in the Swift subclass.
This does not appear to be an issue for a Swift class conforming to the protocol directly, or a Swift subclass of a Swift class that conforms.
Example:
@protocolSomeObjcProtocol <NSObject>
- (instancetype)initWithFoo:(BOOL)foo __attribute__((unavailable("do not use initWithFoo")));
@end
@interfaceSomeObjcClass : NSObject <SomeObjcProtocol>
@end
with an empty implementation of SomeObjcClass, we see
classSomeSwiftSubclass:SomeObjcClass{init(bar:Bool){
super.init()}// Error: "'required' initializer 'init(foo:)' must be provided by subclass of 'SomeObjcClass'"}classAnotherSwiftClass:NSObject,SomeObjcProtocol{init(bar:Bool){
super.init()}// No error}classAnotherSwiftSubclass:AnotherSwiftClass{init(baz:Int){
super.init(bar: true)}// No error}
Inserting the fixit of
requiredinit(foo:Bool){fatalError("init(foo:) has not been implemented")}
allows SomeSwiftSubclass to build. (In fact, it builds without a warning, but that's a separate issue: [SR-2317])
The text was updated successfully, but these errors were encountered:
Attachment: Download
Environment
Tested with identical results in both
Xcode 10.3 / Swift 5.0
Xcode 11 GM / Swift 5.1
Additional Detail from JIRA
md5: eafdeed1bca5c71df626c723596ac258
relates to:
Issue Description:
If you have
a Swift subclass of an ObjC class
where the ObjC class conforms to an ObjC protocol,
the protocol declares an init method marked as
unavailable
,the ObjC class (correctly) does not implement the
unavailable
init method,and the Swift subclass declares its own init method
... the Swift compiler will incorrectly require that the
unavailable
init method be implemented in the Swift subclass.This does not appear to be an issue for a Swift class conforming to the protocol directly, or a Swift subclass of a Swift class that conforms.
Example:
with an empty implementation of SomeObjcClass, we see
Inserting the fixit of
allows SomeSwiftSubclass to build. (In fact, it builds without a warning, but that's a separate issue: [SR-2317])
The text was updated successfully, but these errors were encountered: