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

Superclass constraint 'Self.A' : 'Generic<Self.A>' is recursive

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
      Target: x86_64-apple-darwin18.2.0

      Description

      Swift 5 now allows CRTP. It would be great if CRTP constraints could be formed with associated types of a protocol.

      class Generic<T> {}
      
      protocol P {
        // CRTP with the associated type.
        // I read this as: the conforming type should have a type `A` that
        // is a sub-class of `Generic<A>` (CRTP).
        associatedtype A: Generic<A> // error: Superclass constraint 'Self.A' : 'Generic<Self.A>' is recursive
      }
      

      Forum thread: https://forums.swift.org/t/why-is-this-super-class-constraint-recursive/22340

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              DevAndArtist Adrian Zubarev
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: