[Swift] Declaring function parameter as a generic type conforming specific protocol causes compile-time error

Originator:siarhei.barysenka
Number:rdar://23121865 Date Originated:14-Oct-2015 09:37 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1 beta 3 (7B85), Swift 2.1, OS X 10.11
Classification:Other Bug Reproducible:Always
 
The compiler throws the error "Generic parameter 'T' could not be inferred" at the final line of the attached playground.

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

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) // ERROR: "Generic parameter 'T' could not be inferred"

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!