mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Fix Issue 23384 - Suggest calling matching base class method when hidden (#14525)
* Fix Issue 23384 - Suggest calling matching base class method when hidden * Update compiler/src/dmd/func.d Co-authored-by: Dennis <dkorpel@users.noreply.github.com> Co-authored-by: Dennis <dkorpel@users.noreply.github.com>
This commit is contained in:
parent
4c14051ec6
commit
053e2ee85b
2 changed files with 51 additions and 0 deletions
|
@ -3384,6 +3384,28 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s,
|
|||
// re-resolve to check for supplemental message
|
||||
if (!global.gag || global.params.showGaggedErrors)
|
||||
{
|
||||
if (tthis)
|
||||
{
|
||||
if (auto classType = tthis.isTypeClass())
|
||||
{
|
||||
if (auto baseClass = classType.sym.baseClass)
|
||||
{
|
||||
if (auto baseFunction = baseClass.search(baseClass.loc, fd.ident))
|
||||
{
|
||||
MatchAccumulator mErr;
|
||||
functionResolve(mErr, baseFunction, loc, sc, tiargs, baseClass.type, fargs, null);
|
||||
if (mErr.last > MATCH.nomatch && mErr.lastf)
|
||||
{
|
||||
errorSupplemental(loc, "%s `%s` hides base class function `%s`",
|
||||
fd.kind, fd.toPrettyChars(), mErr.lastf.toPrettyChars());
|
||||
errorSupplemental(loc, "add `alias %s = %s` to `%s`'s body to merge the overload sets",
|
||||
fd.toChars(), mErr.lastf.toPrettyChars(), tthis.toChars());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const(char)* failMessage;
|
||||
functionResolve(m, orig_s, loc, sc, tiargs, tthis, fargs, &failMessage);
|
||||
if (failMessage)
|
||||
|
|
29
compiler/test/fail_compilation/diag23384.d
Normal file
29
compiler/test/fail_compilation/diag23384.d
Normal file
|
@ -0,0 +1,29 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=23384
|
||||
|
||||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/diag23384.d(28): Error: function `diag23384.Derived.fun(B b)` is not callable using argument types `(A)`
|
||||
fail_compilation/diag23384.d(28): function `diag23384.Derived.fun` hides base class function `diag23384.Base.fun`
|
||||
fail_compilation/diag23384.d(28): add `alias fun = diag23384.Base.fun` to `diag23384.Derived`'s body to merge the overload sets
|
||||
---
|
||||
*/
|
||||
|
||||
struct A {}
|
||||
struct B {}
|
||||
|
||||
class Base
|
||||
{
|
||||
void fun(A a) {}
|
||||
}
|
||||
|
||||
class Derived : Base
|
||||
{
|
||||
void fun(B b) {}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
Derived d;
|
||||
d.fun(A());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue