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

Cannot pass in a protocol type to a constrained generic parameter

    XMLWordPrintable

    Details

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

      Swift 3, playground

      Description

      If a generic specifies <T: SomeProtocol>, you cannot pass in an object with type SomeProtocol. This doesn't make sense since presumably, a type should conform to itself.

      To reproduce, put this in a playground:

      protocol P {}
      
      class A: P {}
      
      func foo<T: P>(_ arg: T) {
      }
      
      let a = A()
      foo(a) // compiles
      
      foo(a as P) // fails to compile
      

      Expected: Compilation succeeds
      Actual: Compilation failed

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              plivesey Peter Livesey
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: