Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10186] Swift 5 compiler automatic associatedtype resolution does not work #52588

Closed
swift-ci opened this issue Mar 26, 2019 · 1 comment · Fixed by #59271
Closed

[SR-10186] Swift 5 compiler automatic associatedtype resolution does not work #52588

swift-ci opened this issue Mar 26, 2019 · 1 comment · Fixed by #59271

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 26, 2019

Previous ID SR-10186
Radar rdar://problem/49340036
Original Reporter spiceginger (JIRA User)
Type Bug

Attachment: Download

Environment

XCode version Version 10.2 (10E125), Mojave 10.14.4 (18E226)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.0Regression, AssociatedTypeInference, TypeChecker
Assignee None
Priority Medium

md5: b343bbb0cb6e3110c64efc85f0951d0c

Issue 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

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 24, 2020

Comment by Evgeny Kaz (JIRA)

It still annoying🙁

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant