I can see how this is a problem, but I don't like this solution for the same reasoning that Jordan provided in the bug. Namely, the general rule is that the inner scope shadows the outer scope. This would be a very strange exception that you're proposing.<br><br>I'd rather cope temporarily with the current limitation, which as you mentioned has a workaround everywhere except in Playgrounds; in Playgrounds, there isn't any reason why you couldn't just rename one or the other.<br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 20, 2016 at 13:55 Charlie Monroe via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I've filed this previously as a compiler bug, but was told to discuss this here (<a href="https://bugs.swift.org/browse/SR-1772" target="_blank">https://bugs.swift.org/browse/SR-1772</a>).<div><br></div><div>Motivation:</div><div><br></div><div>Consider the following code:</div><div><br></div><div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">private</span><span> </span><span style="color:#bb2ca2">func</span><span> _validateAccount(name: </span><span style="color:#703daa">String</span><span>, existingAccounts: [</span><span style="color:#703daa">Account</span><span>]) -> </span><span style="color:#703daa">Bool</span><span> {</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span> <font color="#008400">// Logic goes here...</font></span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span>}</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo;min-height:10px"><span></span><br></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">class</span><span> MyController {</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2"> private</span><span> </span><span style="color:#bb2ca2">func</span><span> _validateAccount(name: </span><span style="color:#703daa">String</span><span>) -> </span><span style="color:#703daa">Bool</span><span> {</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2"> </span> <span style="color:rgb(187,44,162)">let</span><span> accounts = self.accounts</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span><br></span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span><span style="white-space:pre-wrap">        </span><font color="#008400">// Error: Extra argument 'existingAccounts' in call</font></span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2"> </span> <span style="color:rgb(187,44,162)">return</span><span> _validateAccount(name, existingAccounts: accounts)</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span> }</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo"><span>}</span></div><div><span><br></span></div><br>_validateAccount(name:, existingAccounts:) is declared at file-level since it is used in two separate controllers (my example comes from an app with accounts and the check is done during creation + when renaming) and then a similar method (with less arguments) is declared on the controllers.</div><div><br></div><div>Currently, the compiler gives an error about ambiguous use of _validateAccount, since it's declared on MyController as well which is taking precedence, even though the number of arguments is different (and the compiler is only checking base names, not arguments).</div><div><br></div><div>As Jordan Rose mentioned in a comment to my report, solution to this is to specify the function using Module._validateAccount, but this is not applicable to Playgrounds.</div><div><br></div><div>This is partially an issue of the ongoing discussion of various name collisions between modules, but in this particular case, it's one single file.</div><div><br></div><div><div>I propose that file-level symbols take precedence over any reference to current type's members, unless explicit self is specified, or at least when it comes to calling a method, the type checker goes up the scope hierarchy to see if there isn't a function satisfying the arguments.</div></div><div><br></div></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>