[swift-evolution] [discussion] What generics feature would this be?

Mathew Huusko V mhuusko5 at gmail.com
Wed Aug 9 14:34:00 CDT 2017


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 <austinzheng at 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 at 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 at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170809/5243abbf/attachment.html>


More information about the swift-evolution mailing list