Open swift-ci opened 5 years ago
Attachment: Download
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,
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:
@protocol SomeObjcProtocol <NSObject> - (instancetype)initWithFoo:(BOOL)foo __attribute__((unavailable("do not use initWithFoo"))); @end @interface SomeObjcClass : NSObject <SomeObjcProtocol> @end
with an empty implementation of SomeObjcClass, we see
class SomeSwiftSubclass: SomeObjcClass { init(bar: Bool) { super.init() } // Error: "'required' initializer 'init(foo:)' must be provided by subclass of 'SomeObjcClass'" } class AnotherSwiftClass: NSObject, SomeObjcProtocol { init(bar: Bool) { super.init() } // No error } class AnotherSwiftSubclass: AnotherSwiftClass { init(baz: Int) { super.init(bar: true) } // No error }
Inserting the fixit of
required init(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])
Comment by Wes Campaigne (JIRA)
Possibly related: SR-6993?
Yeah. This one's going to be tricky to deal with without breaking source compatibility.
@swift-ci create
Attachment: Download
Environment
Tested with identical results in both - Xcode 10.3 / Swift 5.0 - Xcode 11 GM / Swift 5.1Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, ClangImporter | |Assignee | None | |Priority | Medium | md5: eafdeed1bca5c71df626c723596ac258relates 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])