[phobos] hasMember + opDispatch + Uniform Function Call Syntax

Robert Jacques sandford at jhu.edu
Tue Sep 21 10:29:38 PDT 2010


On Sat, 18 Sep 2010 16:36:52 -0400, Philippe Sigaud  
<philippe.sigaud at gmail.com> wrote:

> struct S
> {
>     int ii;
>     int foo(int i) { return ii;}
>     int opDispatch(string s)(int i) { return ii;}
> }
> void main()
> {
>     writeln(typeof(&S.foo).stringof);  // int function(int)
>     writeln(typeof(&S.bar).stringof); // int delegate(int)
> }

Okay this appears to affect any templated function, not just opDispatch. I  
suspect it has something to do with the fact template code gen is not  
universal between modules. For example, if you linked to module B from  
module A, A doesn't know about B's template generate code, so that code  
has(?) to return a delegate. Named member functions, on the other hand  
share a common symbol table. That feels like a weak explanation, so maybe  
it's just a compiler bug. At least the everyday stuff behaves correctly:

      writeln(typeof(&S.init.foo).stringof);
      writeln(typeof(&S.init.bar).stringof);

are both of type int delegate(int).


More information about the phobos mailing list