-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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-1445] Recursive protocol constraints #44054
Comments
Will implementation of this feature allow for instantiation of structs that add a recursive protocol constraint? i.e. protocol Wrapper { associatedtype Wrapped }
indirect enum Foo<Bar: Wrapper> where Bar.Wrapped == Foo { case bar(Bar) } This code currently compiles, but it is impossible to create an instance of `Foo` since you cannot write a type that is parameterized by itself. I guess I would also expect recursive typealiases to work as well.
|
What is the status on this? Seems a critical piece to the generic puzzle. 🙂 Code from a library I'm writing:
All items that are "query bridgeable" should be able to generate ("query") items that are themselves "query bridgeable" so they have access to the same interface. |
Still working on it, but getting a whole lot closer! |
Go Doug Go!! 🙂 |
@davidbjames is there a reason why this wouldn't work for you? public protocol QueryBridgeable {
var query: QueryFactory<QueryBridgeable & Queryable> { get }
func query(_ options: SubQueryOptions) -> QueryFactory<QueryBridgeable & Queryable>
} |
I'm going to mark this as "done" for now. While there are some known bugs (including non-trivial ones!), we've rolled out the feature in the standard library and developers should be able to use it in Swift 4.1. |
Additional Detail from JIRA
md5: 4b84506f25ece4c8bff8423d20b24de5
blocks:
is duplicated by:
relates to:
Issue Description:
From the Generics Manifesto:
Currently, an associated type cannot be required to conform to its enclosing protocol (or any protocol that inherits that protocol). For example, in the standard library SubSequence type of a Sequence should itself be a Sequence:
The compiler currently rejects this protocol, which is unfortunate: it effectively pushes the SubSequence-must-be-a-Sequence requirement into every consumer of SubSequence, and does not communicate the intent of this abstraction well.
The text was updated successfully, but these errors were encountered: