<div dir="ltr"><div><font face="monospace, monospace">func triple(_ x: Int) -> Int {</font></div><div><font face="monospace, monospace"> return 3 * x</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">extension Int {</font></div><div><font face="monospace, monospace"> func triple() -> Int {</font></div><div><font face="monospace, monospace"> return triple(self) // Error here</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div><br></div><div>The error reads:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace">Playground execution failed:<br>error: Test.playground:5:16: error: use of 'triple' refers to instance method 'triple()' rather than global function 'triple' in module '__lldb_expr_52'<br> return triple(self) // Error here<br> ^<br>Test.playground:5:16: note: use '__lldb_expr_52.' to reference the global function in module '__lldb_expr_52'<br> return triple(self) // Error here<br> ^<br> __lldb_expr_52.</font></blockquote><div><br></div><div><br></div><div>Notice where the error says, “use of 'triple' refers to instance method 'triple()' rather than global function 'triple'”.</div><div><br></div><div>Notice further that the instance method takes 0 arguments. In particular, “self.triple()” is a valid way to call it, and “self.triple(self)” is not.</div><div><br></div><div>It is true that the instance method could be called as a type method with 1 argument, “Int.triple(self)”. However, “triple(self)” is not a valid way to call the type method, which we can demonstrate by removing the global function entirely:</div><div><br></div><div><br></div><div><div><font face="monospace, monospace">extension Int {</font></div><div><font face="monospace, monospace"> func triple() -> Int {</font></div><div><font face="monospace, monospace"> return triple(self) // Error here</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div><br></div><div>This time the error reads:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace">Playground execution failed:<br>error: Test.playground:3:23: error: argument passed to call that takes no arguments<br> return triple(self)<br> ~^~~~~</font></blockquote><div><br></div><div><br></div></div><div>So the compiler correctly recognizes that “triple(self)” is not a valid call to the instance method. Indeed, it has the wrong arity. From there, it seems to me a small step to reason that, in the case where a function with the proper signature *does* exist, that it should be called.</div><div><br></div><div> • • •</div><div><br></div><div>Also, as a minor point, going back to the original code, notice there are two diagnostic messages. The second one says, “use '__lldb_expr_52.' to reference the global function”. However, that does not work, and indeed every time I run the playground the number shown changes.</div><div><br></div><div>So it seems that in a playground, the diagnostic is incorrect, as the proposed solution does not work. Is there in fact a way to specify the module for a playground, so as to unambiguously call a global function?</div><div><br></div><div> • • •</div><div><br></div><div>In any case, the proper behavior seems clear-cut to my mind. The shorthand for calling an instance method without “self.” should apply only if there is a matching instance method to call. When there is no instance method which could possibly match, but there is a global function that does, then the unqualified call should resolve to the global function.</div><div><br></div><div>Nevin</div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 24, 2017 at 10:16 PM, Robert Widmann <span dir="ltr"><<a href="mailto:devteam.codafi@gmail.com" target="_blank">devteam.codafi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">If either function had the correct signature and was being properly disambiguated there would not be a diagnostic popped. Can you provide an example of this?<span class="HOEnZb"><font color="#888888"><div><br></div><div>~Robert Widmann</div></font></span><div><div class="h5"><div><br><div><blockquote type="cite"><div>On Sep 24, 2017, at 8:58 PM, Nevin Brackett-Rozinsky <<a href="mailto:nevin.brackettrozinsky@gmail.com" target="_blank">nevin.brackettrozinsky@gmail.<wbr>com</a>> wrote:</div><br class="m_-2883342060042295711Apple-interchange-newline"><div>The new diagnostic is fine, the problem is that there should not be an error at all. If there is only one function with the proper signature, the compiler should not invent a non-existent ambiguity.<div><br></div><div>The situation I encountered involves functions of different arities, so it should be straightforward to select the correct one, yet it still fails to compile. I'd like to make it work.</div><div><br></div><div>Nevin</div><div><br><br>On Sunday, September 24, 2017, Robert Widmann <<a href="mailto:devteam.codafi@gmail.com" target="_blank">devteam.codafi@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This appears to be resolved (in fact, I remember improving this some time ago). I get a much better diagnostic now<br>
<br>
> error: repl.swift:4:16: error: use of 'min' refers to instance method 'min()' rather than global function 'min' in module 'Swift'<br>
> return min(1,2)<br>
> ^<br>
><br>
> repl.swift:4:16: note: use 'Swift.' to reference the global function in module 'Swift'<br>
> return min(1,2)<br>
> ^<br>
> Swift.<br>
<br>
What version of Swift are you still seeing the bad diagnostic in?<br>
<br>
~Robert Widmann<br>
<br>
> On Sep 24, 2017, at 12:03 PM, Nevin Brackett-Rozinsky via swift-dev <<a>swift-dev@swift.org</a>> wrote:<br>
><br>
> I recently got bit by SR-2450, and I’d like to try to fix it. However, I’ve never worked on the compiler before and I have some questions:<br>
><br>
> 1. Is this a reasonable first bug to tackle?<br>
> 2. What resources are available for newcomers to the Swift project?<br>
> 3. What will I need to learn about in order to address SR-2450?<br>
><br>
> Thanks,<br>
><br>
> Nevin<br>
> ______________________________<wbr>_________________<br>
> swift-dev mailing list<br>
> <a>swift-dev@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-dev" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-dev</a><br>
<br>
</blockquote></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div>