D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7958 - Uniform Function Call fails if class defined inside a function
Summary: Uniform Function Call fails if class defined inside a function
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-20 23:30 UTC by thelastmammoth
Modified: 2022-08-16 11:19 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description thelastmammoth 2012-04-20 23:30:22 UTC
//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 thelastmammoth 2012-04-25 00:34:07 UTC
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 hsteoh 2014-08-18 17:30:44 UTC
The original test case now works in DMD git head. However, the one given in comment #1 still doesn't work.
Comment 3 RazvanN 2022-08-16 11:19:43 UTC
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