digitalmars.D.learn - Overriding final functions
- Ary Manzana (19/19) Mar 19 2007 The following code:
- Chris Nicholson-Sauls (9/36) Mar 19 2007 Its not technically a bug, per se, although I agree with you on what wou...
- Ary Manzana (11/47) Mar 20 2007 The strange thing is that in the semantic code you have:
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?
Mar 19 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
Mar 19 2007
Chris Nicholson-Sauls escribió:Ary Manzana wrote:The strange thing is that in the semantic code you have: if (isFinal()) { ... // other checks ... error("...cannot override final..."); ... } So it seems that message would only show if the overriding function also has the final modifier. Strange behaviour...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
Mar 20 2007