Details
-
Type:
Bug
-
Status: Open
-
Priority:
Medium
-
Resolution: Unresolved
-
Component/s: Compiler
-
Environment:
XCode version Version 10.2 (10E125), Mojave 10.14.4 (18E226)
-
Radar URL:
Description
In Swift 5 (and 4.2 compability mode) compiler automatic associatedtype resolution does not work. Compiles fine by swift 4.2 compiler in XCode 10.1.
Implementation of `checkTest(_ viewController: TestViewController, with context: String)` in `ProtocolImplementation` provides to the compiler all the necessary information about `ViewController`/`Context` types. Swift 5 compiler requires it to be specified manually:
import UIKit public protocol SuperProtocol { associatedtype ViewController: UIViewController associatedtype Context func doTest(with context: Context) -> ViewController? } public protocol NestedProtocol: SuperProtocol { associatedtype ViewController associatedtype Context func checkTest(_ viewController: ViewController, with context: Context) -> Bool } public extension NestedProtocol { func doTest(with context: Context) -> ViewController? { return nil } } // Compilation error: // Type 'ProtocolImplementation' does not conform to protocol 'SuperProtocol' // Type 'ProtocolImplementation' does not conform to protocol 'NestedProtocol' class ProtocolImplementation: NestedProtocol { // In swift 5 / 4.2 compability mode this will compile only if you uncomment this typealiases // typealias ViewController = TestViewController // // typealias Context = String func checkTest(_ viewController: TestViewController, with context: String) -> Bool { return true } } class TestViewController: UIViewController { } // Compilation error: // Cannot convert value of type 'String' to expected argument type 'ProtocolImplementation.Context' let vc = ProtocolImplementation().doTest(with: "23")
PS: Worked as expected in the beta version of Xcode 10.2