[swift-evolution] Static Dispatch Pitfalls

Matthew Johnson matthew at anandabits.com
Sat May 21 07:06:52 CDT 2016

Sent from my iPad

On May 21, 2016, at 6:42 AM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:

>> That said, has anyone considered requiring a keyword on the method in the protocol extension that makes it explicit that the dispatch is non-dynamic?
> Many moons ago, I was pushing to require a `final` keyword on protocol extension methods, which would prevent conforming types from providing their own implementations. It was probably the first thing I worked on. There were long arguments about whether and how you could override the `final`-ness, people kept clamoring for dynamic dispatch, and I ultimately wasn't able to produce a consensus before I had to turn my attention back towards paying work.

I agree a keyword here might be useful, but I'm not sure 'final' is the right choice.  The problem with this is that they aren't exactly 'final'.  They can be shadowed by conforming types when the static type of an instance is the concrete type.  Disallowing shadowing by the concrete type is problematic in a number of ways (retroactive modeling, openness of protocol extensions, etc).  

> -- 
> Brent Royal-Gordon
> Architechies
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list