www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - opDispatch with implicit receiver

reply Jacob Carlborg <doob me.com> writes:
Is it supposed to be possible to use opDispatch with an implicit 
receiver? For example:

class Foo
{
     this ()
     {
         foo(3);
     }
     void opDispatch (string name) (int value) {}
}

The above code will fail to compile with the following message:

Error: undefined identifier foo, did you mean class Foo?

If I prepend the call to "foo" with an explicit receiver, i.e. 
"this.foo(3);" the it compiles without errors.

DMD 2.060.

-- 
/Jacob Carlborg
Aug 23 2012
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 08/23/2012 08:30 AM, Jacob Carlborg wrote:
 Is it supposed to be possible to use opDispatch with an implicit
 receiver? For example:

 class Foo
 {
 this ()
 {
 foo(3);
 }
 void opDispatch (string name) (int value) {}
 }

 The above code will fail to compile with the following message:

 Error: undefined identifier foo, did you mean class Foo?

 If I prepend the call to "foo" with an explicit receiver, i.e.
 "this.foo(3);" the it compiles without errors.

 DMD 2.060.

I don't know the actual decision that has been made at the time but I am happy that it works this way. Otherwise the compiler would not be able to flag silly typos in classes that define opDispatch. Yes, it is still possible to make typos after the 'this.' part but at least it is explicit this way. Ali
Aug 23 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-08-23 17:35, Ali Çehreli wrote:

 I don't know the actual decision that has been made at the time but I am
 happy that it works this way. Otherwise the compiler would not be able
 to flag silly typos in classes that define opDispatch. Yes, it is still
 possible to make typos after the 'this.' part but at least it is
 explicit this way.

I see. -- /Jacob Carlborg
Aug 23 2012