<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I created a bug report here: <a href="https://bugs.swift.org/browse/SR-2810" class="">https://bugs.swift.org/browse/SR-2810</a><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Toni</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 30.09.2016 um 19:47 schrieb Mark Lacey <<a href="mailto:mark_lacey@apple.com" class="">mark_lacey@apple.com</a>>:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; 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=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Sep 30, 2016, at 5:02 AM, Toni Suter via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi,<div class=""><br class=""></div><div class="">I am trying to get a better understanding of Swift's function overload resolution rules.</div><div class="">As far as I can tell, if there are multiple candidates for a function call, Swift favors</div><div class="">functions for which the least amount of parameters have been ignored / defaulted. For example:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">// Example 1</font></div><div class=""><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">func f(x: Int) { print("f1") }</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">func f(x: Int, y: Int = 0) { print("f2") }</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">f(x: 0)<span class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">        </span>// f1</font></div></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><br class=""></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">// Example 2</font></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">func f(x: Int, y: Int = 0) { print("f1") }</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">func f(x: Int, y: Int = 0, z: Int = 0) { print("f2") }</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">f(x: 0)<span class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">        </span>// f1</font></div></div><div class=""><br class=""></div><div class="">It also looks like Swift favors functions with default-value parameters over functions with variadic parameters:</div><div class=""><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><br class=""></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">func f(x: Int = 0) { print("f1") }</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">func f(x: Int...) { print("f2") }</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><br class=""></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">f()<span class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">                        </span>// f1</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">f(x: 1)<span class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">                </span>// f1</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">f(x: 1, 2)<span class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">                </span>// f2 (makes sense because f1 would not work here)</font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="">f(x: 1, 2, 3)<span class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">                </span>// f2 </font><span class="" style="font-family: Menlo;">(makes sense because f1 would not work here)</span></div></div><div class=""><br class=""></div><div class="">But then I tested functions with default-value parameters and variadic parameters and things start to get weird.</div><div class="">For example, this must be a bug, right?</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">func f(x: Int..., y: Int = 0) { print(x, y) }</font></div><div class=""><font face="Menlo" class="">func f(x: Int...) { print(x) }</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">f()<span class="Apple-tab-span" style="white-space: pre;">                        </span>// []</font></div><div class=""><font face="Menlo" class="">f(x: 1)<span class="Apple-tab-span" style="white-space: pre;">                        </span>// [1]</font></div><div class=""><font face="Menlo" class="">f(x: 1, 2)<span class="Apple-tab-span" style="white-space: pre;">                </span>// [1, 2] 0</font></div><div class=""><font face="Menlo" class="">f(x: 1, 2, 3)<span class="Apple-tab-span" style="white-space: pre;">                </span>// [1, 2, 3]</font></div></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class="">I think, in this example, it should always call the second overload, because</div><div class="">no parameter is ignored / defaulted. What do you think?</div></div></div></blockquote><div class=""><br class=""></div>Can you open a new bug report for this at<span class="Apple-converted-space"> </span><a href="http://bugs.swift.org/" class="">bugs.swift.org</a>?</div><div style="font-family: Helvetica; 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 class=""></div><div style="font-family: Helvetica; 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="">Mark</div><div style="font-family: Helvetica; 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 class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">Thanks and best regards,</div><div class="">Toni</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></div></blockquote></div></div></blockquote></div><br class=""></div></body></html>