Swift 4.1: Init class fails when used from a protocol associated type
Originator: | acapulco1988 | ||
Number: | rdar://39237693 | Date Originated: | April 6 2018 |
Status: | Open | Resolved: | |
Product: | Developer Tools | Product Version: | Swift 4.1, Xcode 9.3 |
Classification: | Serious | Reproducible: | Always |
Summary: Initializing a class from protocol associated type fails with "Use of unimplemented initializer". Steps to Reproduce: Create a macOS playground with the following code: import Cocoa protocol Component: class { static func createView() -> NSView } protocol GenericComponent: Component { associatedtype CoreClassAlias: NSView } class ParentView: NSView { init(custom: Int) { super.init(frame: .zero) } required init?(coder aDecoder: NSCoder) { fatalError("Not implemented") } } class CustomView: ParentView { init() { super.init(custom: 0) } required init?(coder aDecoder: NSCoder) { fatalError("Not implemented") } } class ConcreteComponent: Component, GenericComponent { typealias CoreClassAlias = CustomView } extension GenericComponent { static func createTypedView() -> CoreClassAlias { return CoreClassAlias.init() } static func createView() -> NSView { return createTypedView() } } var components: [Component.Type] = [ ConcreteComponent.self ] let generic = components[0] let normalInitWorks = CustomView() let thisDoesntWork = generic.createView() Expected Results: Either compiles and works, or doesn't compile and gives a reason. Actual Results: Compiles, doesn't work. InitFailWithMetatype_macOS.playground: 11: 7: Fatal error: Use of unimplemented initializer 'init(frame:)' for class '__lldb_expr_48.ParentView' Version/Build: Swift 4.1, Xcode 9.3 Configuration: Default
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!