opDispatch returning this not working in a hierarchy

Daniel L. Alves daniel_lopes_alves at hotmail.com
Wed Feb 1 20:00:19 PST 2012


Hi,
I don't know if this is really a bug or some gotcha of the language that I
don't get. I'm sorry if it happens to be the later.

When I run this simple program

class DispatchBase
{
    auto opDispatch( string m, Args... )( Args  args )
    {
        writefln( "Tried to call %s", m );
        return this;
    }
}

class DispatchDerived : DispatchBase
{
    void printValue( T )( T value )
    {
        writefln( "Value is %s", value );
    }
}

void main()
{
    DispatchBase base = new DispatchDerived();
    base.items.printValue( true );
}

I receive this output

Tried to call items
Tried to call printValue

But what I was expecting is

Tried to call items
Value is true

After all, opDispatch returns 'this'. The interesting thing is that when I
move opDispatch up to DispatchDerived, everything works fine. It's like 'this'
inside opDispatch didn't recognize its real type when in a base class.

Hope you can help me.
Daniel


More information about the Digitalmars-d-bugs mailing list