Uploaded image for project: 'Swift'
  1. Swift
  2. SR-1445

Recursive protocol constraints

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
      None

      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:

      protocol Sequence {
        associatedtype Iterator : IteratorProtocol
        ...
        associatedtype SubSequence : Sequence   // currently ill-formed, but should be possible
      }
      

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                DougGregor Doug Gregor
                Reporter:
                hartbit David Hart
              • Votes:
                7 Vote for this issue
                Watchers:
                13 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: