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-1065] Lack of associatedType namespacing leads to surprising errors #43677

Open
swift-ci opened this issue Mar 25, 2016 · 3 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself feature A feature request or implementation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1065
Radar None
Original Reporter nblake (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 0c2607d11e5f61e44888e564de443735

Issue Description:

When an entity adopts from two protocols that share an associatedType, surprising errors result from namespacing issues.

protocol A {
    associatedtype T
    var aT: T { get }
}

protocol B {
    associatedtype T
    var bT: T { get }
}

Type C does not conform to protocol 'B'.

class C: A, B {
    var aT = String()
    var bT = Int()
}

Compiles without error.

class C: A, B {
    var aT = String()
    var bT = String()
}

Type C does not conform to protocol 'A'.

class C: A, B {
    typealias T = Int
    var aT = String()
    var bT = Int()
}

I would offer that I consider this a low priority or trivial issue, but undesirable behavior nonetheless.

@belkadan
Copy link
Contributor

Any change here would have to go through the Swift Evolution Process.

@jckarter
Copy link
Member

jckarter commented Apr 7, 2016

This is a general problem with naming collisions between protocols. We could provide an attribute to let you satisfy a requirement with a different name, e.g.:

class C: A, B {
    @implements(A.T)
    typealias AT = String
    @implements(B.T)
    typealias BT = Int
    var aT = String()
    var bT = Int()
}

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 7, 2016

Comment by Noah Blake (JIRA)

Thanks for your feedback. Actually, it's very similar to what I had in mind.

In the case that I described, it should also be possible for the user to omit

@implements(A.T)
typealias AT = String
@implements(B.T)
typealias BT = Int

The compiler, using type inferencing, would simply sugar it in. In fact, I'm hoping the user probably will only need to use the new attribute you've proposed in rare cases.

For what it's worth, I've also tried to begin a discussion through the [mailing list](https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160404/014209.html).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 feature A feature request or implementation
Projects
None yet
Development

No branches or pull requests

3 participants