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

AnyObject constraint on generic type parameter doesn't work when a protocol type is passed as an argument

    XMLWordPrintable

    Details

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

      Xcode 10, Swift 4

      Description

      When passing a protocol as an argument, it may be useful to know whether it has reference semantics, but there does not appear to be a way to do this in Swift. The following code does not compile but should:

      protocol Foo: class {
      }
      
      func use<P: AnyObject>(type: P.Type) {
      }
      
      // Does not compile
      use(type: Foo.self)
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              revolucent Gregory Higley
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: