[swift-users] Swift 4 protocol with associatedtype conforming to itself

Slava Pestov spestov at apple.com
Wed Jun 7 02:47:35 CDT 2017


> On Jun 7, 2017, at 12:46 AM, Jens Persson <jens at bitcycle.com> wrote:
> 
> Ok, I thought it was part of SE-0142 (which has status "implemented (Swift 4)”.

That’s just the where clause part. There’s still plenty you can accomplish with them even if they do not introduce recursive conformances :)

Slava

> /Jens
> 
> On Wed, Jun 7, 2017 at 9:39 AM, Slava Pestov <spestov at apple.com <mailto:spestov at apple.com>> wrote:
> This is a rather complex feature that is not actually implemented in Swift 4 (or Swift 3 for that matter). Work is underway to support this, though. The fact that the second example does not produce a diagnostic is a bug (probably you will not be able to define a type that conforms to P2 anyway).
> 
> The proposal is here if you’d like to read more about it: https://github.com/apple/swift-evolution/blob/master/proposals/0157-recursive-protocol-constraints.md <https://github.com/apple/swift-evolution/blob/master/proposals/0157-recursive-protocol-constraints.md>
> 
> Slava
> 
> > On Jun 6, 2017, at 10:37 PM, Jens Persson via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> >
> > In Swift 4:
> >
> > protocol P1 {
> >     associatedtype A: P1 // Error: Type may not reference itself as a requirement
> > }
> > protocol P2 {
> >     associatedtype A where A: P2 // OK
> > }
> >
> > What is the rationale behind this?
> >
> > /Jens
> > _______________________________________________
> > swift-users mailing list
> > swift-users at swift.org <mailto:swift-users at swift.org>
> > https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170607/0d0f064d/attachment.html>


More information about the swift-users mailing list