Struct with opDispatch doesn't dispatch. Is this a bug?

cal callumenator at gmail.com
Thu Jul 4 22:03:51 PDT 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.)


More information about the Digitalmars-d-learn mailing list