UFCS should work with local symbols

Timothee Cour thelastmammoth at gmail.com
Wed Mar 12 19:57:05 PDT 2014


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
  }
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140312/3d7e4b19/attachment-0001.html>


More information about the Digitalmars-d mailing list