[swift-evolution] [Draft] Introducing StaticSelf, an Invariant Self

Nicola Salmoria nicola.salmoria at gmail.com
Fri May 13 13:11:12 CDT 2016

On Fri, May 13, 2016 at 12:55 PM, Vladimir.S <svabox at gmail.com> wrote:

> > I'm not convinced by this example.
> Probably my & Matthew's previous discussion in `[swift-evolution] [RFC]
> #Self` topic will help you. I was trying there to find out (in primitive
> examples) what Matthew is trying to achive with this `->StaticSelf` in
> protocol.
> In two words - he wants to achieve requirement 'return Self class or any
> of base classes', as current `->Self` requires 'strictly return Self class'

I think I understand what the request is, but I'm not sure if it's a
problem worth solving, and if this would be the right solution.

Going back to the example, let's say you have the requested

protocol Fooable {
    func foo() -> StaticSelf

class A: Fooable {
    func foo() -> A { return A() }

class B: A {

How would you use foo() in generic code?

func bar<T: Fooable>(_ x: T) -> X {
    return x.foo()

What does bar() return? What do you put in place of X in its declaration?
You can't use T, you can't use T.StaticSelf. So what's the purpose of
having a protocol if you can't use it in generic code?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160513/f33b31ad/attachment.html>

More information about the swift-evolution mailing list