override requires no return inference

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 14 14:24:42 PDT 2016


A question asked in D.learn about this. I'm confused why this is not 
allowed, but seems to be specifically called out in the error.

Ex:

class A
{
     auto foo() { return true; }
}

class B : A
{
     override auto foo() { return false; }
}

Error: function testproperty.B.foo return type inference is not 
supported if may override base class function

I tried this:

class B : A
{
     override bool foo() { return false; }
}

And I get this:

Error: function testproperty.B.foo does not override any function, did 
you mean to override 'testproperty.A.foo'?

Huh? This seems to be a bug actually. I assumed the issue was that A.foo 
was inferring pure, nothrow, etc. So I did this:

pragma(msg, typeof(A.foo))

And then it compiled!

But the first error seems tailored to apply to this situation. My 
question is, why? What harm are we fixing by preventing return type 
inference in overriding functions?

-Steve


More information about the Digitalmars-d mailing list