No bug here, I think. opDispatch takes precedence and just fails to compile.
The same thing happens with
---
struct Foo {
void bar() {}
}
---
The error message could be improved though. foo.opDispatch is a template. It's foo.opDispatch!"bar" that is not.
Comment #2 by dransic — 2013-01-05T09:05:00Z
(In reply to comment #1)
> opDispatch takes precedence and just fails to compile.
Obviously. But is it really by design?
This works, where opDispatch does not take precedence:
---
struct Foo {
void opDispatch(string s)() {}
}
void baz(Foo f) {}
unittest {
Foo foo;
foo.baz(); // OK
}
---
Comment #3 by k.hara.pg — 2013-01-05T09:12:16Z
(In reply to comment #2)
> (In reply to comment #1)
> > opDispatch takes precedence and just fails to compile.
>
> Obviously. But is it really by design?
>
> This works, where opDispatch does not take precedence:
> ---
> struct Foo {
> void opDispatch(string s)() {}
> }
>
> void baz(Foo f) {}
>
> unittest {
> Foo foo;
> foo.baz(); // OK
> }
> ---
Just *template* opDispach is required for operator overloading. Therefore non-template function is simply ignored.
Comment #4 by dransic — 2013-01-05T09:17:39Z
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > opDispatch takes precedence and just fails to compile.
> >
> > Obviously. But is it really by design?
> >
> > This works, where opDispatch does not take precedence:
> > ---
> > struct Foo {
> > void opDispatch(string s)() {}
> > }
> >
> > void baz(Foo f) {}
> >
> > unittest {
> > Foo foo;
> > foo.baz(); // OK
> > }
> > ---
>
> Just *template* opDispach is required for operator overloading. Therefore
> non-template function is simply ignored.
Yes. I understand why it doen't work at the moment. I just found it inconsistent. Maybe this should be an enhancement request then...
Comment #5 by simen.kjaras — 2013-01-05T12:19:17Z
(In reply to comment #2)
> This works, where opDispatch does not take precedence:
> ---
> struct Foo {
> void opDispatch(string s)() {}
> }
>
> void baz(Foo f) {}
>
> unittest {
> Foo foo;
> foo.baz(); // OK
> }
Except, of course, opDispatch *does* take precedence here. Try this instead:
import std.stdio : writeln;
struct Foo {
void opDispatch(string s)() { writeln("opDispatch: ", s); }
}
void baz(Foo f) { writeln("function: baz"); }
void main( ) {
Foo foo;
foo.baz(); // OK
}
I can assure you it prints opDispatch: baz.
Comment #6 by dransic — 2013-01-06T04:49:57Z
(In reply to comment #5)
> (In reply to comment #2)
> > This works, where opDispatch does not take precedence:
> > ---
> > struct Foo {
> > void opDispatch(string s)() {}
> > }
> >
> > void baz(Foo f) {}
> >
> > unittest {
> > Foo foo;
> > foo.baz(); // OK
> > }
>
> Except, of course, opDispatch *does* take precedence here. Try this instead:
>
> import std.stdio : writeln;
>
> struct Foo {
> void opDispatch(string s)() { writeln("opDispatch: ", s); }
> }
>
> void baz(Foo f) { writeln("function: baz"); }
>
> void main( ) {
> Foo foo;
> foo.baz(); // OK
> }
>
> I can assure you it prints opDispatch: baz.
Ah! I was trapped by the minimalism of my example. OK thanks.