[swift-users] Weird function call behaviour

David Hart david.w.hart at me.com
Wed Feb 22 15:01:27 CST 2017


> On 22 Feb 2017, at 21:59, Slava Pestov via swift-users <swift-users at swift.org> wrote:
> 
> When a class conforms to a protocol and a requirement is fulfilled by a method in an extension, the class does not get a vtable entry for the extension method. So it cannot be overridden in a subclass — there’s nothing to dynamically dispatch here. We plan on addressing this as part of ABI stability.

What do you mean by “address” this? Force the vtable entry?

> Slava
> 
> 
>> On Feb 22, 2017, at 9:39 AM, David Hart via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> 
>> In the following piece of code, can somebody explain the last result? Why the break in consistency? Is this a bug?
>> 
>> protocol P {
>> 	func foo() -> String
>> }
>> 
>> extension P {
>> 	func foo() -> String { return "P" }
>> }
>> 
>> class A : P {
>> 	func foo() -> String { return "A" }
>> }
>> 
>> class B : P {}
>> class C : B {
>> 	func foo() -> String { return "C" }
>> }
>> 
>> A().foo()          // A
>> (A() as P).foo()   // A
>> B().foo()          // P
>> (B() as P).foo()   // P
>> C().foo()          // C
>> (C() as P).foo()   // P
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org <mailto:swift-users at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170222/0ab3e5cf/attachment.html>


More information about the swift-users mailing list