I'd like to have UFCS work with local symbols, it would be more orhogonal and make the following work:
int front(int[] arr) { return arr[0]; }
void main() {
int[] a = [1,2,3];
auto x = a.front(); // call .front by UFCS
auto front = x; // front is now a variable
auto y = a.front(); // Error, front is not a function
//EDIT: error (same behavior as if we had outside : import std.array:front; auto front=1;)
//EDIT: another example:
auto front(int[]b){return b;}
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.
}
class C {
int[] arr;
int front() {
return arr.front(); // Error, C.front is not callable
// using argument types (int[])
//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
}
}
}