Bug 7958 – Uniform Function Call fails if class defined inside a function

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-20T23:30:22Z
Last change time
2022-08-16T11:19:43Z
Assigned to
No Owner
Creator
thelastmammoth

Comments

Comment #0 by thelastmammoth — 2012-04-20T23:30:22Z
//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; }
Comment #1 by thelastmammoth — 2012-04-25T00:34:07Z
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 }
Comment #2 by hsteoh — 2014-08-18T17:30:44Z
The original test case now works in DMD git head. However, the one given in comment #1 still doesn't work.
Comment #3 by razvan.nitu1305 — 2022-08-16T11:19:43Z
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