[swift-evolution] [Discussion] Allowing extending existentials

Slava Pestov spestov at apple.com
Wed Feb 22 01:30:25 CST 2017


> On Feb 21, 2017, at 10:53 PM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello list,
> 
> Found out yesterday that you can’t extend all existentials in Swift:
> 
> protocol P1 {}
> extension P1 {}
> // works as expected
> 
> protocol P2 {}
> extension P1 & P2 {}
> // error: non-nominal type 'P1 & P2' cannot be extended

This will make name lookup rather complicated. I’d rather not do it. As Jacob mentions, you can almost simulate it with a constrained extension.

> 
> extension Any {}
> // error: non-nominal type 'Any' cannot be extended
> 
> extension AnyObject {}
> // error: 'AnyObject' protocol cannot be extended

These two are by design. In the future, AnyObject will be ‘special’ (basically we want to model it as ‘Any & class’), and not a protocol.

Slava

> 
> I’d like to write a proposal to lift some of those restrictions. But the question is: which should be lifted? P1 & P2 seems like an obvious case. But what about Any and AnyObject? Is there a design reason that we shouldn’t allow it?
> 
> David.
> _______________________________________________
> 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/20170221/76ee2f30/attachment.html>


More information about the swift-evolution mailing list