Thread overview
opDispatch with implicit receiver
Aug 23, 2012
Jacob Carlborg
Aug 23, 2012
Ali Çehreli
Aug 24, 2012
Jacob Carlborg
August 23, 2012
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
August 23, 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

August 24, 2012
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