www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - override requires no return inference

reply Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Apr 14 2016
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 14.04.2016 23:24, Steven Schveighoffer wrote:
 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?
AFAIK it's supposed to work, but it is currently not supported by DMD: https://issues.dlang.org/show_bug.cgi?id=8318
Apr 14 2016