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-5166] typealias prevents compilation of generic protocol implementation #47742

Closed
chezzdev opened this issue Jun 8, 2017 · 2 comments
Closed
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

@chezzdev
Copy link

chezzdev commented Jun 8, 2017

Previous ID SR-5166
Radar rdar://problem/32666189
Original Reporter @chezzdev
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.0 beta (9M136h) / Swift 4

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

md5: cfb76c549862be9e9b6052ff16e701c6

relates to:

  • SR-5016 Swift 4: Unable to satisfy associated type requirements implicitly
  • SR-5104 Protocol's associatedtype not correctly inferred when the type is a closure argument

Issue Description:

I've experienced a problem during Swift 3.1 to Swift 4 codebase migration.

The problem arrises when I try to implement a generic protocol method that takes a closure with a generic parameter with a protocol as an associated type.

The following code works fine in Swift 3.1:

protocol FooType {
    associatedtype BarType

    func foo(bar: BarType)
    func foo(action: (BarType) -> Void)
}

protocol Bar {}

class Foo: FooType {
    typealias BarType = Bar

    // Compiles in both 3.1 and 4
    func foo(bar: Bar) {
    }

    // Swift 4 error: Candidate has non-matching type (Bar) -> Void
    func foo(action: (Bar) -> Void) {     
    }
}

However in Swift 4 compiler gives me an error about class Foo not conforming to protocol FooType with foo(action: ) method implementation missing.

By the way Xcode 9 "fix-it" generates the same implementation I have.

It's possible to workaround the issue by removing the line

typealias BarType = Bar

which is ok since type inference does its job, but nevertheless it should be a valid code.

@belkadan
Copy link
Contributor

belkadan commented Jun 9, 2017

Thanks, Alexander.

@swift-ci create

@belkadan
Copy link
Contributor

Fixed in
master: #10441
4.0: #10447

@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