Navigation Menu

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-4143] Swift 3.1 compatibility issue with associated types #46726

Closed
swift-ci opened this issue Mar 2, 2017 · 7 comments
Closed

[SR-4143] Swift 3.1 compatibility issue with associated types #46726

swift-ci opened this issue Mar 2, 2017 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 2, 2017

Previous ID SR-4143
Radar rdar://problem/30809983
Original Reporter tomquist (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Version 8.3 beta 3 (8W132p)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, 3.1Regression
Assignee tomquist (JIRA)
Priority Medium

md5: cca0f12afad932a5539ca9e5735fe772

Issue Description:

The following snipped worked in Swift 3.0, but doesn't compile in Swift 3.1

protocol XType {
    associatedtype Value
    func doX(_ value1: Value, _ value2: Value) -> Bool
}
protocol YType {
    associatedtype Value
    func doY(_ value: Value)
}

protocol A: Equatable {
    associatedtype X: XType
    static var x: X { get }
}

protocol B: A {
    associatedtype Y: YType
    static var y: Y { get }
}

extension B where Y == X {
    static var x: X {
        return y
    }
}
struct X<T> {
    typealias Value = T
}
struct Y<T> {
    typealias Value = T
}
extension X: XType {
    func doX(_ value1: Value, _ value2: Value) -> Bool { return true }
}
extension Y: XType {
    func doX(_ value1: Value, _ value2: Value) -> Bool { return true }
}
extension Y: YType {
    func doY(_ value: T) {}
}

func ==<T: A>(lhs: T, rhs: T) -> Bool where T.X.Value == T {
    return T.x.doX(lhs, rhs)
}

struct M: B {
    static var y: Y<M> {
        return Y()
    }
}

Error:
Type 'M' does not conform to protocol 'A'. Protocol requires nested type 'X'; do you want to add it?
Type 'M' does not conform to protocol 'Equatable'

This lead to the following issue in my library: tomquist/Equals#6

@jckarter
Copy link
Member

jckarter commented Mar 2, 2017

@swift-ci create

@jckarter
Copy link
Member

jckarter commented Mar 2, 2017

Smaller repro:

protocol A {
    associatedtype X
    associatedtype Y
    static var x: X { get }
    static var y: Y { get }
}
extension A where Y == X {
    static var x: X {
        return y
    }
}

struct M: A {
    static var y: Int {
        return 0
    }
}

@jckarter
Copy link
Member

jckarter commented Mar 2, 2017

Might be fallout from my associated type inference cleanups. We may be prematurely rejecting the `extension B where X == Y` as a candidate for default implementations.

@jckarter
Copy link
Member

jckarter commented Mar 2, 2017

Fix for master: #7875

@jckarter
Copy link
Member

jckarter commented Mar 2, 2017

For 3.1 branch: #7877

@jckarter
Copy link
Member

jckarter commented Mar 3, 2017

Should be fixed in future snapshots.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 3, 2017

Comment by Tom Quist (JIRA)

Wow, that was fast. Thanks! Will try the next snapshot asap.

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

No branches or pull requests

2 participants