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-9692] Error attempting to use initializer in protocol extension from a factory method #52133

Closed
swift-ci opened this issue Jan 17, 2019 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9692
Radar None
Original Reporter Anandabits (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 56631fedda30488c3501d53e75ad5cb2

Issue Description:

struct S: RP {
    typealias R = S
    typealias A = Int
}
protocol KP {
    associatedtype R: RP
    associatedtype A
}
protocol RP: KP where R == Self {
    associatedtype R = Self
}
protocol R1: RP {}
protocol R2: RP {}
protocol HK {
    associatedtype K: KP
}
protocol HK2: HK {}
struct H<K: KP>: HK {}

extension HK where K.R: R2 {
    init<T: HK>(h t: T) where T.K.R == K.R, T.K.A == K.A {
        // implementation doesn't matter
        fatalError()
    }
}

extension H where K.R: R1 {
    static func h<T: HK>(_ t: T) -> H where T.K.R == K.R, T.K.A == K.A {
        // Member 'init' in 'H<K>' produces result of type 'Self', but context expects 'H<K>'
        return .init(h: t)
    }
}
@belkadan
Copy link
Contributor

cc @xedin

@xedin
Copy link
Member

xedin commented Jan 31, 2019

Anandabits (JIRA User) I tried this on 5.0 branch and this is what it's currently producing:

error: referencing initializer 'init(h:)' on 'HK' requires that 'K.R' conform to 'R2'
        return .init(h: t)
                ^
note: where 'Self.K.R' = 'K.R'
extension HK where K.R: R2 {
^

Does that make more sense?

@swift-ci
Copy link
Collaborator Author

Comment by Matthew Johnson (JIRA)

@xedin yeah that makes a lot more sense. Glad to see improvements to the diagnostics coming in Swift 5, thanks!

@xedin
Copy link
Member

xedin commented Jan 31, 2019

No problem!.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants