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

protocol associatedtype where-clause rules not consistent with direct colon constraint rules

    XMLWordPrintable

    Details

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

      Xcode Version 9.0 beta 3 (9M174d)

      Description

      This is illegal:

      protocol Flier {
          associatedtype Other : Flier // compile error
          func flockTogetherWith(f:Other)
      }
      

      I've never liked that restriction and have complained about it before. Well, I'm surprised to find that in Swift 4 I can evade the restriction by using a `where` clause instead:

      protocol Flier {
          associatedtype Other where Other : Flier // fine!
          func flockTogetherWith(f:Other)
      }
      

      Before I start relying on this workaround, though, I have to ask: is this intentional? It doesn't seem like it. Why on earth should there be a restriction on the direct colon constraint but not on the equivalent `where` clause? Thus I fear that this may be an oversight.

      (I also fear that in calling this to your attention you will close the loophole on my workaround. I'd rather you didn't do that. I'd prefer that the restriction were lifted altogether.)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                mattneub Matt Neuburg
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: