opDispatch with implicit receiver

Ali Çehreli acehreli at yahoo.com
Thu Aug 23 08:35:10 PDT 2012


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



More information about the Digitalmars-d-learn mailing list