Is this a bug in overload resolution?

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Mar 30 04:53:03 PDT 2012


class Foo
{
    bool test() { return true; }
}

class Bar
{
    this() { foo = new Foo; }
    Foo foo;
    alias foo this;
}

class FooBar : Bar
{
    bool test(int x) { return true; }
    alias super.test test;
}

void main() {}

test.d(17): Error: 'this' is only defined in non-static member
functions, not FooBar
test.d(17): Error: alias test.FooBar.test cannot alias an expression
(__error).foo.test

The error message is odd. I'm trying to bring in the overloads of the
'test' function from the base class. But it doesn't seem to work if
the overloads are in an 'alias this' field and not the base class
itself.

If I comment out the "alias super.test test;" line I can access the
function from the 'foo' subtype:
void main()
{
    auto foobar = new FooBar;
    foobar.Bar.test();  // calls 'foo.test'
}

So I'm thinking "alias super.test test;" should work. Bug?


More information about the Digitalmars-d-learn mailing list