Very interesting. Is this likely to be changed in the future (either
existentials conforming to their protocols, or `S: Protocol` specifically
allowing for existentials)?

Also, is this at all related? Another instance of at naive/face value
something seeming like it should conform, but not..

protocol Special {}
protocol SubSpecial: Special {}

let spec: Special.Protocol = Special.self // works
let subspec: Special.Protocol = SubSpecial.self // doesnt work



On Wed, Aug 9, 2017 at 7:17 PM, Austin Zheng <austinzh...@gmail.com> wrote:

> A existential type of some protocol `P`, counterintuitively, doesn't
> conform to itself, unless it's an Objective-C protocol.
>
> Because `S : Special` means S has to be a type that conforms to the
> protocol `Special`, and `special` is of the existential type `Special`, the
> existential type `Special` doesn't conform to the protocol `Special`, so it
> can't be used for `S`.
>
> Best,
> Austin
>
> > On Aug 9, 2017, at 7:19 AM, Mathew Huusko V via swift-evolution <
> swift-evolution@swift.org> wrote:
> >
> >
> > Curious what part of generics the below would fall under? This hit me by
> surprise/makes even non-generic/Self-depending protocols un-interchangeable
> with classes..
> >
> > ```
> > protocol Special {}
> >
> > func doWithAndReturn<S: Special>(_ special: S) -> S { ... }
> >
> > let special: Special = ...
> >
> > // "error: Generics parameter 'S' could not be inferred"
> > // works fine when 'Special' is a class
> > let newSpecial: Special = doWithAndReturn(special)
> > ```
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to