www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Struct with opDispatch doesn't dispatch. Is this a bug?

reply "Meta" <jared771 gmail.com> writes:
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'
}
Jul 04 2013
next sibling parent "cal" <callumenator gmail.com> writes:
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.)
Jul 04 2013
prev sibling parent "Kenji Hara" <k.hara.pg gmail.com> writes:
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
Jul 04 2013