Overriding final functions
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Mon Mar 19 22:46:26 PDT 2007
Ary Manzana wrote:
> The following code:
>
> class X {
>
> public final void bla() {
> }
>
> }
>
> class Y : X {
>
> public override void bla() {
> }
>
> }
>
> gives:
>
> main.d(10): function main.Y.bla function bla does not override any
>
> I'd expect the error to be:
>
> main.d(10): function main.Y.bla cannot override final function main.X.bla
>
> (which I do get if I put the "final" keyword in bla on class Y)
>
> Am I misunderstanding something or this is a bug?
Its not technically a bug, per se, although I agree with you on what would have been the
more intuitive error message -- and perhaps that should be filed as a suggestion. The
general logic behind seems to be this: 'override' usurps virtual methods, and 'final'
makes a method non-virtual. So for the internal checks of 'override' there is no
'/*(virtual)*/ void bla()' to match.
Slightly screwy, but understandable. I would think it straightforward to add a
last-resort check for matching 'final'/non-virtual methods.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list