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

non-@objc protocol existentials do not conform to their own protocol type

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None

      Description

      Summary:
      The compiler throws the error

      generic parameter 'T' could not be inferred
      

      at the final line of the following code:

      protocol MediaProtocol {}
      protocol ImageProtocol: MediaProtocol {}
      
      class Image: ImageProtocol {}
      
      func itemToProcess() -> ImageProtocol {
          return Image()
      }
      
      //func process<T>(item: T) -> T { // Uncomment this line and comment out the following one to remove the compile-time error
      func process<T: MediaProtocol>(item: T) -> T {
          return item
      }
      
      let image = itemToProcess()
      let processedImage: ImageProtocol = process(image)
      

      The error is gone when conformance to `MediaProtocol` is removed from the generic type `T` at the `process` method declaration in the given code.

      Reproduced on:
      Xcode 7.1.1 (7B1005), Swift 2.1, OS X 10.11

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                slavapestov Slava Pestov
                Reporter:
                siarhei.barysenka Siarhei Barysenka
              • Votes:
                35 Vote for this issue
                Watchers:
                39 Start watching this issue

                Dates

                • Created:
                  Updated: