SR-55 non-@objc protocol existentials do not conform to their own protocol type
Issue 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:
protocolP {}
classA: P {}
funcfoo<T: P>(_arg: T) {
}
leta = A()
foo(a) // compilesfoo(aasP) // fails to compile
This is correct in the general case: not all protocols conform to themselves. The simplest case is a protocol with initializer requirements: which concrete type would you construct?
But for protocols that do allow this, is it okay to use them in this way? It's tricky.
I did wonder if there was a edge case like that that I hadn't forseen. That does make sense.
Presumably, Swift doesn't currently split between these types of protocols (reasonable). In that case, is it possible to have another error message for this? Like: "Protocol types cannot be used as a variable bound to a generic constraint." Or something like that which is worded better and more correct terminology?
Environment
Swift 3, playground
Additional Detail from JIRA
md5: 2fb3ab1d24786f3528652546206fc0aa
duplicates:
Issue 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:
Expected: Compilation succeeds
Actual: Compilation failed
The text was updated successfully, but these errors were encountered: