Thread overview
Struct with opDispatch doesn't dispatch. Is this a bug?
Jul 05, 2013
Meta
Jul 05, 2013
cal
Jul 05, 2013
Kenji Hara
July 05, 2013
I wasn't 100% sure the following is a bug, so I figured I'd ask.

struct Fail
{
	void opDispatch(string s)()
	{
		static assert(false, "Tried to call a method on Fail");
	}
}

void main()
{
        auto fail = Fail();
        fail.s(); //Error: no property 's' for type 'Fail'
}
July 05, 2013
On Friday, 5 July 2013 at 03:12:44 UTC, Meta wrote:
> I wasn't 100% sure the following is a bug, so I figured I'd ask.
>
> struct Fail
> {
> 	void opDispatch(string s)()
> 	{
> 		static assert(false, "Tried to call a method on Fail");
> 	}
> }
>
> void main()
> {
>         auto fail = Fail();
>         fail.s(); //Error: no property 's' for type 'Fail'
> }

Are you asking why the compiler doesn't halt at the static assert (and instead gives a 'no property' error)? (If you just want the code to compile and trigger a runtime assert due to the method call, remove the static from the assert line, and the dispatch will occur.)
July 05, 2013
On Friday, 5 July 2013 at 03:12:44 UTC, Meta wrote:
> I wasn't 100% sure the following is a bug, so I figured I'd ask.
>
> struct Fail
> {
> 	void opDispatch(string s)()
> 	{
> 		static assert(false, "Tried to call a method on Fail");
> 	}
> }
>
> void main()
> {
>         auto fail = Fail();
>         fail.s(); //Error: no property 's' for type 'Fail'
> }

This is a compiler's diagnostic bug.
http://d.puremagic.com/issues/show_bug.cgi?id=10546

In this case, opDispatch is _actually_ instantiated. However the static assertion message is suppressed for later UFCS symbol search.
But UFCS cannot find module level function 's', then compiler reports irrelevant error message "no property 's'"

Kenji Hara