<div dir="ltr">The same ambiguity occurs even without inheritance:<div><br></div><div><div>class C {</div><div> func foo() {}</div><div> func foo(x: Int = 0) {}</div><div>}</div></div><div><br></div><div>Somewhat related: <a href="https://bugs.swift.org/browse/SR-1408">https://bugs.swift.org/browse/SR-1408</a></div><div><br></div><div class="gmail_extra">
<br><div class="gmail_quote">On Wed, Jan 4, 2017 at 7:42 PM, Wagner Truppel via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>I’m afraid I wasn’t clear enough on my post. The default value I referred to is the “= 0”. Had it been absent, the call c.foo() would undeniably be fulfilled by the parent class. However, with the default argument value, it’s not obvious whether c.foo() should be the parent’s implementation or the child’s implementation (with the argument set to the default value). That’s why I’m suggesting a compiler warning because it’s very easy to make the mistake of calling c.foo() expecting the child’s implementation and it may be a hard bug to track when it happens.</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>Wagner</div></font></span><div><div class="gmail-h5"><div><br></div><br><div><blockquote type="cite"><div>On 5 Jan 2017, at 03:35, Saagar Jha <<a href="mailto:saagar@saagarjha.com" target="_blank">saagar@saagarjha.com</a>> wrote:</div><br class="gmail-m_8991309594834202044Apple-interchange-newline"><div><div style="word-wrap:break-word">I’m not quite sure what you mean by "restrictions of parent implementations”, however, the “default value” you’re mentioning is a fundamental part of OOP–when a subclass overrides a superclass, it gets the parent class’s methods for free. There’s no need to issue a warning for this, since it’s expected behavior from other Object-Oriented languages.<div>
<br class="gmail-m_8991309594834202044Apple-interchange-newline"><span style="font-family:"sf ui text";font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">Saagar Jha</span><br style="font-family:"sf ui text";font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:"sf ui text";font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:"sf ui text";font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
</div>
<br><div><blockquote type="cite"><div>On Jan 4, 2017, at 6:29 PM, Wagner Truppel via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br class="gmail-m_8991309594834202044Apple-interchange-newline"><div><div>Hello,<br><br>I wasn’t sure whether to post this message here, at swift-dev, or at swift-evolution. so I’ll try here first. Hopefully it will get to the right group of people or, if not, someone will point me to the right mailing list.<br><br>I came across a situation that boils down to this example:<br><br>class Parent {<br> func foo() {<br> print("Parent foo() called")<br> }<br>}<br><br>class Child: Parent {<br> func foo(x: Int = 0) {<br> print("Child foo() called")<br> }<br>}<br><br>let c = Child()<br>c.foo() // prints "Parent foo() called"<br><br>I understand why this behaves like so, namely, the subclass has a method foo(x:) but no direct implementation of foo() so the parent’s implementation is invoked rather than the child's. That’s all fine except that it is not very intuitive.<br><br>I would argue that the expectation is that the search for an implementation should start with the subclass (which is does) but should look at all possible restrictions of parent implementations, including the restriction due to default values.<br><br>At the very least, I think the compiler should emit a warning or possibly even an error.<br><br>Thanks for reading.<br>Cheers,<br><br>Wagner<br>______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></div></blockquote></div><br></div></div></blockquote></div><br></div></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div></div>