[Issue 23377] class method overloading with same name doesn't work for base classes
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Sep 26 19:43:13 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23377
Paul Backus <snarwin+bugzilla at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |snarwin+bugzilla at gmail.com
--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
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"));
---
--
More information about the Digitalmars-d-bugs
mailing list