Thread overview
[phobos] hasMember + opDispatch + Uniform Function Call Syntax
Sep 18, 2010
David Simcha
Sep 18, 2010
Philippe Sigaud
Sep 21, 2010
Robert Jacques
September 17, 2010
  http://d.puremagic.com/issues/show_bug.cgi?id=4880

The patch here will work for now, but I don't want to commit it because long-term uniform function call syntax will break it.  Any ideas for how to introspect whether someStruct.someMember() compiles as an actual member function, not a uniform syntax rewrite of a free function call? Of course you could check hasMember, opDispatch, (isPointer && hasMember!(pointerTarget)), etc., but I'd rather avoid lots of brittle special casing because, as both this and hasAliasing and friends show, you always seem to miss a few cases.
September 18, 2010
I just discovered that someStruct.someMethod and someStruct.opDispatch!("someMethod") don't have the same type. Strange.

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)
}

Anyone knows why?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100918/7da9a505/attachment.html>
September 21, 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).