<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 22, 2017, at 1:01 PM, David Hart &lt;<a href="mailto:david.w.hart@me.com" class="">david.w.hart@me.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 22 Feb 2017, at 21:59, Slava Pestov via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">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.</div></div></div></blockquote><div class=""><br class=""></div><div class="">What do you mean by “address” this? Force the vtable entry?</div></div></div></div></blockquote><div><br class=""></div>Yeah. Instead of having the witness table for the conformance point directly to the extension method, if the conforming type is a class, we will generate a small thunk that calls a vtable entry, and store the extension method in that vtable entry.</div><div><br class=""></div><div>Of course this will only work if the conformance is defined in the same translation unit as the class; if you define the extension in a different module, you’ll get the same behavior you observe below.</div><div><br class=""></div><div>Slava</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Slava</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 22, 2017, at 9:39 AM, David Hart via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">In the following piece of code, can somebody explain the last result? Why the break in consistency? Is this a bug?<div class=""><br class=""></div><div class=""><font face="Menlo" class="">protocol&nbsp;P {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>func&nbsp;foo() -&gt;&nbsp;String<br class="">}<br class=""><br class="">extension&nbsp;P&nbsp;{<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>func&nbsp;foo() -&gt;&nbsp;String&nbsp;{&nbsp;return&nbsp;"P"&nbsp;}<br class="">}<br class=""><br class="">class&nbsp;A :&nbsp;P&nbsp;{<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>func&nbsp;foo() -&gt;&nbsp;String&nbsp;{&nbsp;return&nbsp;"A"&nbsp;}<br class="">}<br class=""><br class="">class&nbsp;B :&nbsp;P&nbsp;{}<br class="">class&nbsp;C :&nbsp;B&nbsp;{<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>func&nbsp;foo() -&gt;&nbsp;String&nbsp;{&nbsp;return&nbsp;"C"&nbsp;}<br class="">}<br class=""><br class="">A().foo() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// A<br class="">(A()&nbsp;as&nbsp;P).foo() &nbsp; // A<br class="">B().foo() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// P<br class="">(B()&nbsp;as&nbsp;P).foo() &nbsp; // P<br class="">C().foo() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// C<br class="">(C()&nbsp;as&nbsp;P).foo() &nbsp; // P</font></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>