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

T: Protocol generic constraint doesn't accept protocol existentials

    XMLWordPrintable

    Details

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

      swift 3.0, both in xcode 8 and in the swiftc 3 toolchain.

      Description

      I would expect the following to compile. The protocol used as an existential type should also conform to the constraint given in the generic function concrete.

      However, it gives the error: error: cannot invoke 'concrete' with an argument list of type '(P)'

      protocol P {
          func go()
      }
      
      extension String: P {
          func go() {
              print("String")
          }
      }
      extension Int: P {
          func go() {
              print("Int")
          }
      }
      
      func concrete<T: P>(_ a: T) {
          a.go()
      }
      
      func abstract(a: P) {
          concrete(a)
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              chadaustin Chad Austin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: