[swift-evolution] Making protocol conformance inheritance controllable

Chris Lattner clattner at apple.com
Thu Dec 10 23:22:34 CST 2015


On Dec 10, 2015, at 6:04 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> To mitigate these issues, I'd like to float the idea that protocol conformances *not be* inherited by default. If you declare a class as conforming to a protocol, only exactly that class can be bound to a type parameter constrained by that protocol:
> 
> protocol Runcible {}
> class A: Runcible { }
> class B : A { }
> 
> func foo<T: Runcible>(x: T) {}
> 
> foo(B()) // calls foo with T == A
> 
> Since subclasses are still subtypes of the base class, in many cases client code won't have to change at all, since derived instances can implicitly upconvert to their conforming base class when used in protocol types or generics that only the base class conforms to.

Very interesting approach, I think I like it.  That said, this is subtle enough that we’d probably have to prototype it to see what falls out in practice on existing real world code.

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151210/450baf31/attachment.html>


More information about the swift-evolution mailing list