The problem is confusing the common placeholder, limited by the protocol, with the protocol itself. Here is a simple example similar to your code to make it clearer:
Why is this not compiling?
How common functions work, during compilation, when you call a function, the compiler decides what type the placeholder T should be and then writes you a function with all the occurrences of T replaced by that type.
So, in the example below, T should be replaced by S1 :
let obj1: S1 = g()
It looks ok. Also, what if we want T be S2 ? S2 corresponds to P , so this is an absolutely legal value for T But how could this work:
Here is the source of the error message you receive. Your placeholder A may be present for any type that conforms to Protocol , but you are trying to return a specific type ( AClass ) that conforms to this protocol. So this will not allow you to do this.
source share