Non-conflicting derived class overload shadows base class method
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Mon Mar 20 12:57:03 PDT 2017
Is this a bug?
class A {
int method();
}
class B : A {
override void method(int);
}
void main() {
B b;
b.method(123); // OK
int x = b.method(); // NG
}
One might question the wisdom of this kind of overloading, but this is
an actual use case in Phobos. In std.range.interfaces, we have:
interface InputRange(E) {
@property bool empty();
@property E front(); // N.B. argumentless overload
void popFront();
}
interface InputAssignable(E) : InputRange!E {
@property void front(E e); // single argument overload
}
The current shadowing behaviour makes InputAssignable fail to pass
isInputRange, because the derived interface's .front method shadows the
base class's, even though they are non-conflicting overloads(!).
T
--
"I'm running Windows '98." "Yes." "My computer isn't working now." "Yes, you already said that." -- User-Friendly
More information about the Digitalmars-d
mailing list