Bug 23384 – Suggest calling matching base class method when hidden
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2022-10-03T13:13:25Z
Last change time
2022-10-06T09:39:28Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Nick Treleaven
Comments
Comment #0 by nick — 2022-10-03T13:13:25Z
struct A {}
struct B {}
class Base
{
void fun(A a) {}
}
class Derived : Base
{
void fun(B b) {}
}
void main()
{
Derived d;
d.fun(A());
}
The above code (rightly IMO) produces this error:
overloadhiding.d(18): Error: function `overloadhiding.Derived.fun(B b)` is not callable using argument types `(A)`
overloadhiding.d(18): cannot pass argument `A()` of type `A` to parameter `B b`
This sometimes gets reported as a suspected compiler bug, e.g. bug 23377 (closed as WONTFIX) or on the forum.
After the error message for Derived.fun(A), the compiler should add an informational message when the base class has a match, explaining that match is hidden. That would help the user know the workaround and also make it clear the error is by design. (I had a look but I'm not sure how to implement it).
Comment #1 by dlang-bot — 2022-10-06T02:16:51Z
@RazvanN7 updated dlang/dmd pull request #14525 "Fix Issue 23384 - Suggest calling matching base class method when hidden" fixing this issue:
- Fix Issue 23384 - Suggest calling matching base class method when hidden
https://github.com/dlang/dmd/pull/14525