//this works class A{ int x; } int fun(A a){return a.x;} void main(){A a=new A; auto x=a.fun;} //this doesn't work: unittest{ class A{ int x; } int fun(A a){return a.x;} A a=new A; auto x=a.fun; }
EDIT: more importantly, it also fails if fun() is defined inside a function: //this doesn't work: class A{ int x; } void myfunction(){ int fun(A a){return a.x;} A a=new A; auto x=a.fun; //fails }
The original test case now works in DMD git head. However, the one given in comment #1 still doesn't work.
This bug report is not valid as per the spec [1] (point 7): "Functions declared in a local scope are not found when searching for a matching UFCS function. Neither are other local symbols, although local imports are searched." [1] https://dlang.org/spec/function.html#pseudo-member