digitalmars.D - UFCS should work with local symbols
- Timothee Cour (37/37) Mar 12 2014 I'd like to have UFCS work with local symbols, it would be more orhogona...
I'd like to have UFCS work with local symbols, it would be more orhogonal
and make the following work:
void main(){
void fun(string a){}
"".fun;//CT error currently
}
unittest{
void fun(string a){}
"".fun;//CT error currently
}
in http://dlang.org/function.html there is some explanation why this isn't
allowed however I don't find it convincing (see my added comments with
//EDIT):
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
}
}
}
Mar 12 2014








Timothee Cour <thelastmammoth gmail.com>