https://issues.dlang.org/show_bug.cgi?id=23377

Paul Backus <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #1 from Paul Backus <[email protected]> ---
Simplified example:

---
void main()
{
    Derived d;
    A a;
    d.fun(a);
}

struct A {}
struct B {}
struct C {}

class Base
{
    void fun(A a) {}
    void fun(C c) {}
}

class Derived : Base
{           
    // if you comment this it will call Base.fun(A)
    void fun(B b) {}
}
---

I think what's happening here is that Base.fun and Derived.fun are in separate
overload sets, and the derived-class overload set shadows the base-class one.
Examining the overload sets with reflection appears to support this hypothesis:

---
struct A {}
struct B {}
struct C {}

class Base
{
    void fun(A a) {}
    void fun(C c) {}
}

class Derived1 : Base
{           
    // if you comment this it will call Base.fun(A)
    void fun(B b) {}
}

// prints: tuple(fun)
pragma(msg, __traits(getOverloads, Derived1, "fun"));

class Derived2 : Base {}

// prints tuple(fun, fun)
pragma(msg, __traits(getOverloads, Derived2, "fun"));
---

--

Reply via email to