mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
Fix : Improved error message on override mismatch (#21023)
This commit is contained in:
parent
49198f2983
commit
8663b6dcdc
2 changed files with 57 additions and 0 deletions
|
@ -983,6 +983,43 @@ void funcDeclarationSemantic(Scope* sc, FuncDeclaration funcdecl)
|
||||||
|
|
||||||
error(funcdecl.loc, "function `%s` does not override any function, did you mean to override `%s`?",
|
error(funcdecl.loc, "function `%s` does not override any function, did you mean to override `%s`?",
|
||||||
funcdeclToChars, buf1.peekChars());
|
funcdeclToChars, buf1.peekChars());
|
||||||
|
|
||||||
|
// Supplemental error for parameter scope differences
|
||||||
|
auto tf1 = cast(TypeFunction)funcdecl.type;
|
||||||
|
auto tf2 = cast(TypeFunction)fd.type;
|
||||||
|
|
||||||
|
if (tf1 && tf2)
|
||||||
|
{
|
||||||
|
auto params1 = tf1.parameterList;
|
||||||
|
auto params2 = tf2.parameterList;
|
||||||
|
|
||||||
|
if (params1.length == params2.length)
|
||||||
|
{
|
||||||
|
bool hasScopeDifference = false;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < params1.length; i++)
|
||||||
|
{
|
||||||
|
auto p1 = params1[i];
|
||||||
|
auto p2 = params2[i];
|
||||||
|
|
||||||
|
if ((p1.storageClass & STC.scope_) == (p2.storageClass & STC.scope_))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(p2.storageClass & STC.scope_))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!hasScopeDifference)
|
||||||
|
{
|
||||||
|
// Intended signature
|
||||||
|
errorSupplemental(funcdecl.loc, "Did you intend to override:");
|
||||||
|
errorSupplemental(funcdecl.loc, "`%s`", buf1.peekChars());
|
||||||
|
hasScopeDifference = true;
|
||||||
|
}
|
||||||
|
errorSupplemental(funcdecl.loc, "Parameter %d is missing `scope`",
|
||||||
|
cast(int)(i + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
20
compiler/test/fail_compilation/test20489.d
Normal file
20
compiler/test/fail_compilation/test20489.d
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
TEST_OUTPUT:
|
||||||
|
---
|
||||||
|
fail_compilation/test20489.d(19): Error: function `pure nothrow @nogc @safe int test20489.D.f(int delegate(int) pure nothrow @nogc @safe body)` does not override any function, did you mean to override `pure nothrow @nogc @safe int test20489.B.f(scope int delegate(int) pure nothrow @nogc @safe)`?
|
||||||
|
fail_compilation/test20489.d(19): Did you intend to override:
|
||||||
|
fail_compilation/test20489.d(19): `pure nothrow @nogc @safe int test20489.B.f(scope int delegate(int) pure nothrow @nogc @safe)`
|
||||||
|
fail_compilation/test20489.d(19): Parameter 1 is missing `scope`
|
||||||
|
---
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Test case for https://github.com/dlang/dmd/issues/20489
|
||||||
|
// Improved error message on override mismatches
|
||||||
|
|
||||||
|
class B {
|
||||||
|
pure nothrow @nogc @safe int f(scope int delegate(int) pure nothrow @nogc @safe) { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class D : B {
|
||||||
|
override pure nothrow @nogc @safe int f(int delegate(int) pure nothrow @nogc @safe body) { return 0; }
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue