<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Nov 14, 2016, at 16:05, Toni Suter via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii">Hi,<div class=""><br class=""></div><div class="">I would have expected that the following code reports an error, because</div><div class="">of ambiguous function overloads:<br class=""><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">infix operator ***: MultiplicationPrecedence</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">infix operator +++: AdditionPrecedence</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">func ***(x: Int, y: Int) -> String {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("f1")</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return ""</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">}</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">func ***(x: Int, y: Int) -> Int {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("f2")</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return 0</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">}</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">func +++(x: String, y: Int) -> Int {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("f3")</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return 0</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">}</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">func +++(x: Int, y: Int) -> Int {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("f4")</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return 0</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">}</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">let result = 0 *** 4 +++ 0<span class="Apple-tab-span" style="white-space:pre">                </span>// prints f2 and f4</font></div></div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">As far as I can tell, there are two possible overload resolutions: f1 + f3 or f2 + f4.</div><div class="">I thought that these two solutions get an "equivalent score" and therefore there would</div><div class="">be a compile error. However, that's not the case. Instead, the type checker picks</div><div class="">f2 and f4.</div><div class=""><br class=""></div><div class="">So, I guess my question is, whether there is some rule, that prefers</div><div class="">operators, which have the same argument types and the same return type</div><div class="">or whether this is simply a bug.</div></blockquote><br><div>Odd... Perhaps the compiler is convinced the result of the *** operation needs to be an Int? Dunno why that would be, though.</div><div><br></div><div>What happens if you split it up into two statements?</div><div><br></div><div>- Dave Sweeris </div></body></html>