<div dir="ltr"><div>I'd like to have UFCS work with local symbols, it would be more orhogonal and make the following work:</div><div>void main(){<br></div><div> void fun(string a){}</div><div> "".fun;//CT error currently</div>
<div>}</div><div><br></div><div>unittest{</div><div> void fun(string a){}</div><div> "".fun;//CT error currently</div><div>}</div><div><br></div><div>in <a href="http://dlang.org/function.html">http://dlang.org/function.html</a> there is some explanation why this isn't allowed however I don't find it convincing (see my added comments with //EDIT):<br>
</div><div><br></div><div><div>int front(int[] arr) { return arr[0]; }</div><div><br></div><div>void main() {</div><div> int[] a = [1,2,3];</div><div> auto x = a.front(); // call .front by UFCS</div><div><br></div><div>
auto front = x; // front is now a variable</div><div> auto y = a.front(); // Error, front is not a function</div><div><br></div><div>//EDIT: error (same behavior as if we had outside : import std.array:front; auto front=1;)</div>
<div><br></div><div>//EDIT: another example:</div><div><div> auto front(int[]b){return b;}</div></div><div><div> auto y = a.front(); // since a isn't a class instance that has a front method, call front(a), which is the nested function front.</div>
</div><div>}<br></div><div><br></div><div>class C {</div><div> int[] arr;</div><div> int front() {</div><div> return arr.front(); // Error, C.front is not callable</div><div> // using argument types (int[])</div>
<div> //EDIT: why not error: front is ambiguous or even accept the code as calling the front() defined outside based on usual disambiguation rules based on types</div><div> }</div><div>}</div><div>}</div></div><div><br>
</div><div><br></div></div>