Inheritance of purity
kenji hara
k.hara.pg at gmail.com
Fri Feb 17 06:13:54 PST 2012
I have thought a reverse case.
class C
{
@safe const void f(){}
}
class D : C
{
override void f(){} // inferred as @safe const?
// 'override' keyword must be required for override method?
void f(){} // @system and mutable?
// Adding mutable version in derived class should work?
// Does no override keyword should mean always "new root of overriding"?
}
I think the lack of 'override' keyword (filed as bug 3836) should
become an error, without the phase of deprecating it. Otherwise
following case will be allowed.
class C
{
const void f(){}
}
class D : C
{
void f(){}
// in 2.058 Error: function test.D.f of type void() overrides
but is not
// covariant with test.C.f of type const void()
// in 2.059? overrides C.foo implicitly!!
// Although bug 3836 will be fixed with deprecating, -d
option allows this annoying overriding.
// It is worse than 2.058 and before.
}
Kenji Hara
2012/2/17 kenji hara <k.hara.pg at gmail.com>:
> I think this is a current implementation problem.
>
> In this case, just `override void foo()` in class D should override
> the method in C.
> And `void foo()const` should be a new overlodad of foo.
>
> Kenji Hara
>
> 2012/2/17 Timon Gehr <timon.gehr at gmx.ch>:
>> On 02/17/2012 02:33 PM, Timon Gehr wrote:
>>>
>>>
>>> Introducing a new overload against const in a subclass is illegal:
>>>
>>> class C{
>>> void foo(){}
>>> }
>>> class D : C{
>>> override void foo(){}
>>> override void foo()const{}
>>> }
>>>
>>> Error: D.foo multiple overrides of same function
>>
>>
>> Oops...
>>
>> I meant
>>
>>
>> class C{
>> void foo(){}
>> }
>>
>> class D:C{
>> override void foo(){}
>> void foo()const{}
>> }
>>
>> The error message is the same though.
More information about the Digitalmars-d
mailing list