BCS wrote:
Hello Walter,
Andrei Alexandrescu wrote:
Second, the new rule is simple: if the overriding function can be
called with the overriden function's arguments, it is overriding it.
True, things get more complicated when the base class also defines a
corresponding overload:
class A {
void fun(A);
void fun(B);
}
class B : A {
override void fun(A);
}
This must be either an error, or the case that B.fun overrides both
overloads of fun in A.
I would really want to get away from the notion of selecting which
function is overridden based on being a "better" match.
a torture test:
class B
{
void Fn (D,B) {}
void Fn (B,D) {}
}
class D : B
{
void Fn(B,B) {} // override D,B or B,D?
}
This is simple - it overrides both. There are more complicated cases
with longer inheritance chains and overloads defined in the derived
classes.
I think it's ok to hold off contravariance for now.
Andrei