On Monday, 11 September 2017 at 18:15:36 UTC, jmh530 wrote:
An interesting example. I'm not sure overriding is the issue so most as what is in the overload set. I think foo(int) is not part of the overload set yet. The compiler is able to cast the long to int and then call the one in class B without needing to look to the base class. The behavior is also the same if you use alias this (below).

It's just an issue (not really an issue :) of name lookup. First, compiler searches for names, that is, for something called "foo". Then, when it finds "foo" (or several in the same scope), it does overload resolution on them. If those are wrong names, it just reports an error, for example:

class A {
    final void foo(int) {
        writeln("A.foo(int)");
    }
}

class B : A {
    string foo = "bar";
}

void main() {
    B b = new B;
    int n = 1;
    b.foo(n);
}

While looking for names, it doesn't even care if "foo" is a function or whatever.


Would there be any problems with final functions of inherited or alias this types being included in the overload set?


I don't know, maybe don't use alias this :) IMO, it's a really dubious feature...

Reply via email to