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

Constraints involving a Class & Protocol constraint don't type check correctly

    XMLWordPrintable

    Details

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

      Xcode 10.2b3

      macOS 10.14.3

      Description

       

      protocol P {}
      func f<C: Collection>(objects: C) where C.Element : NSObject & P {}
      let objects: [NSObject & P] = []
      _ = f(objects: objects)
      
      

      results in:
       

      class-and-protocol-constraint.swift:24:5: error: global function 'f(objects:)' requires that 'NSObject' conform to 'P'
      _ = f(objects: objects)
          ^
      class-and-protocol-constraint.swift:21:6: note: where 'C.Element' = 'NSObject'
      func f<C: Collection>(objects: C) where C.Element : NSObject & P {}
           ^
      

       
      This also fails in Xcode 10.1, but with a different and stranger error message.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              tjw Timothy Wood
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: