<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="">Ahh, I get what you’re saying now. In this case I’d like to see a warning when a “conflicting” function is defined that there may be potential ambiguity.<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Saagar Jha</span><br style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Jan 4, 2017, at 8:19 PM, Wagner Truppel <<a href="mailto:trupwl@gmail.com" class="">trupwl@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Indeed, and in this case as well the compiler issues no warning even though the ambiguity is evident. I had to try it on a playground to be sure that it’s the parameter-less foo() rather than the default-argumented foo(x:) that gets invoked when we call foo() on an instance.<br class=""><br class="">Of course, both this ambiguity and the one I started with can be resolved by explicitly calling foo(x: 0) but, as that link points out, "What is the point of having an optional parameter (a parameter with a default value) if you have to supply it anyway?”<br class=""><br class="">More importantly, it’s an easy mistake to expect one implementation to be invoked rather than the other, with a potentially costly impact. The compiler has enough information to catch this and I think it should.<br class=""><br class="">Wagner<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 5 Jan 2017, at 03:54, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>> wrote:<br class=""><br class="">The same ambiguity occurs even without inheritance:<br class=""><br class="">class C {<br class=""> func foo() {}<br class=""> func foo(x: Int = 0) {}<br class="">}<br class=""><br class="">Somewhat related: <a href="https://bugs.swift.org/browse/SR-1408" class="">https://bugs.swift.org/browse/SR-1408</a><br class=""><br class=""><br class="">On Wed, Jan 4, 2017 at 7:42 PM, Wagner Truppel via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class="">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.<br class=""><br class="">Wagner<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 5 Jan 2017, at 03:35, Saagar Jha <<a href="mailto:saagar@saagarjha.com" class="">saagar@saagarjha.com</a>> wrote:<br class=""><br class="">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.<br class=""><br class="">Saagar Jha<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On Jan 4, 2017, at 6:29 PM, Wagner Truppel via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""><br class="">Hello,<br class=""><br class="">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 class=""><br class="">I came across a situation that boils down to this example:<br class=""><br class="">class Parent {<br class=""> func foo() {<br class=""> print("Parent foo() called")<br class=""> }<br class="">}<br class=""><br class="">class Child: Parent {<br class=""> func foo(x: Int = 0) {<br class=""> print("Child foo() called")<br class=""> }<br class="">}<br class=""><br class="">let c = Child()<br class="">c.foo() // prints "Parent foo() called"<br class=""><br class="">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 class=""><br class="">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 class=""><br class="">At the very least, I think the compiler should emit a warning or possibly even an error.<br class=""><br class="">Thanks for reading.<br class="">Cheers,<br class=""><br class="">Wagner<br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></blockquote><br class=""></blockquote><br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""><br class=""><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></body></html>