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-5104] Protocol's associatedtype not correctly inferred when the type is a closure argument #47680

Closed
nsalmoria opened this issue Jun 6, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.0

Comments

@nsalmoria
Copy link
Contributor

Previous ID SR-5104
Radar rdar://problem/32617656
Original Reporter @nsalmoria
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9 beta 1

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

md5: e2edf34ed298b6b93cdf371c7823d0c9

duplicates:

  • SR-5016 Swift 4: Unable to satisfy associated type requirements implicitly

relates to:

  • SR-5166 typealias prevents compilation of generic protocol implementation

Issue Description:

SE-0110 seems to be confusing the compiler in this situation:

  • a protocol has an associated type

  • the protocol requires a method whose argument is a function

  • the argument of the methods's function is the associated type.

Under those conditions, the associated type seems to be inferred to be a "single element tuple" (which doesn't exist in Swift).

protocol A {
    associatedtype E
    func f(_: (E) -> Void)
}

// error: type 'B<E>' does not conform to protocol 'A'
// note: candidate has non-matching type '<E> ((E) -> Void) -> ()' [with E = (E)]
struct B<E>: A {
    func f(_: (E) -> Void) {
    }
}

// error: type 'C<V>' does not conform to protocol 'A'
// note: candidate has non-matching type '<V> ((V) -> Void) -> ()' [with E = (V)]
struct C<V>: A {
    func f(_: (V) -> Void) {
    }
}

Note that the compiler fix-it offers to create a stub for the function it thinks to be missing, which however causes another compile error:

    // error: invalid redeclaration of 'f'
    func f(_: ((E)) -> Void) {
    }

the workaround is to explicitly declare a typealias for the associated type:

// OK
struct D<V>: A {
    typealias E = V
    func f(_: (V) -> Void) {
    }
}
@belkadan
Copy link
Contributor

belkadan commented Jun 7, 2017

@swift-ci create

@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 regression swift 4.0
Projects
None yet
Development

No branches or pull requests

3 participants