www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a bug in overload resolution?

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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?
Mar 30 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 03/30/2012 01:53 PM, Andrej Mitrovic wrote:
 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?
Smells like a bug in the property function call syntax implementation.
Mar 30 2012