Skip to content

Commit ffac30e

Browse files
committed
Fixes Some Issue to pass other testcases
1 parent e89c130 commit ffac30e

File tree

2 files changed

+22
-44
lines changed

2 files changed

+22
-44
lines changed

compiler/src/dmd/funcsem.d

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -984,24 +984,20 @@ void funcDeclarationSemantic(Scope* sc, FuncDeclaration funcdecl)
984984
error(funcdecl.loc, "function `%s` does not override any function, did you mean to override `%s`?",
985985
funcdeclToChars, buf1.peekChars());
986986

987-
// A more detailed error message showing the difference between signatures
987+
// Only add supplemental error for parameter scope differences
988988
auto tf1 = cast(TypeFunction)funcdecl.type;
989989
auto tf2 = cast(TypeFunction)fd.type;
990990

991-
// Only show diff if both are function types
992991
if (tf1 && tf2)
993992
{
994-
// Get parameter lists
995993
auto params1 = tf1.parameterList;
996994
auto params2 = tf2.parameterList;
997995

998-
// Show the function signature that would be correct
999-
errorSupplemental(funcdecl.loc, "Did you intend to override:");
1000-
errorSupplemental(funcdecl.loc, "`%s`", buf1.peekChars());
1001-
1002-
// If parameter counts match, show detailed diff for each parameter
996+
// Only check for scope differences if parameter counts match
1003997
if (params1.length == params2.length)
1004998
{
999+
bool hasScopeDifference = false;
1000+
10051001
for (size_t i = 0; i < params1.length; i++)
10061002
{
10071003
auto p1 = params1[i];
@@ -1011,16 +1007,19 @@ void funcDeclarationSemantic(Scope* sc, FuncDeclaration funcdecl)
10111007
if ((p1.storageClass & STC.scope_) != (p2.storageClass & STC.scope_))
10121008
{
10131009
if (p2.storageClass & STC.scope_)
1010+
{
1011+
if (!hasScopeDifference)
1012+
{
1013+
// Only show the intended signature once
1014+
errorSupplemental(funcdecl.loc, "Did you intend to override:");
1015+
errorSupplemental(funcdecl.loc, "`%s`", buf1.peekChars());
1016+
hasScopeDifference = true;
1017+
}
10141018
errorSupplemental(funcdecl.loc, "Parameter %d is missing `scope`", cast(int)(i + 1));
1019+
}
10151020
}
10161021
}
10171022
}
1018-
else
1019-
{
1020-
// If parameter counts don't match, show that
1021-
errorSupplemental(funcdecl.loc, "Parameter count mismatch: %d vs %d",
1022-
cast(int)params1.length, cast(int)params2.length);
1023-
}
10241023
}
10251024
}
10261025
}
Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
11
/*
2+
REQUIRED_ARGS: -verrors=0
23
TEST_OUTPUT:
34
---
4-
fail_compilation/test20489.d(23): Error: function `pure nothrow @nogc @safe int test20489.D1.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.B1.f(scope int delegate(int) pure nothrow @nogc @safe)`?
5-
fail_compilation/test20489.d(23): Did you intend to override:
6-
fail_compilation/test20489.d(23): `pure nothrow @nogc @safe int test20489.B1.f(scope int delegate(int) pure nothrow @nogc @safe)`
7-
fail_compilation/test20489.d(23): Parameter 1 is missing `scope`
8-
fail_compilation/test20489.d(32): Error: function `test20489.D2.nonExistentMethod` does not override any function
9-
fail_compilation/test20489.d(41): Error: function `test20489.D3.finalMethod` cannot override `final` function `test20489.B3.finalMethod`
10-
fail_compilation/test20489.d(41): Error: function `void test20489.D3.finalMethod()` does not override any function, did you mean to override `void test20489.B3.finalMethod()`?
11-
fail_compilation/test20489.d(41): Did you intend to override:
12-
fail_compilation/test20489.d(41): `void test20489.B3.finalMethod()`
5+
fail_compilation/test20489.d(20): 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)`?
6+
fail_compilation/test20489.d(20): Did you intend to override:
7+
fail_compilation/test20489.d(20): `pure nothrow @nogc @safe int test20489.B.f(scope int delegate(int) pure nothrow @nogc @safe)`
8+
fail_compilation/test20489.d(20): Parameter 1 is missing `scope`
139
---
1410
*/
1511

12+
// Test case for https://issues.dlang.org/show_bug.cgi?id=20489
13+
// Improved error message for override mismatches
1614

17-
// Case 1: Signature mismatch (parameter attributes)
18-
class B1 {
15+
class B {
1916
pure nothrow @nogc @safe int f(scope int delegate(int) pure nothrow @nogc @safe) { return 0; }
2017
}
2118

22-
class D1 : B1 {
19+
class D : B {
2320
override pure nothrow @nogc @safe int f(int delegate(int) pure nothrow @nogc @safe body) { return 0; }
2421
}
25-
26-
// Case 2: No base class method with the given name exists
27-
class B2 {
28-
void existingMethod() {}
29-
}
30-
31-
class D2 : B2 {
32-
override void nonExistentMethod() {}
33-
}
34-
35-
// Case 3: Base class method is final
36-
class B3 {
37-
final void finalMethod() {}
38-
}
39-
40-
class D3 : B3 {
41-
override void finalMethod() {}
42-
}

0 commit comments

Comments
 (0)