Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes Issue 9191 - Wrong diagnostic on failing override.

For failing overrides the compiler should look for similar symbols in the
base classes and interfaces, and not the current class.
  • Loading branch information...
commit 5bcba1f0ff22786d47dacf7f24d9d9231291ef7c 1 parent b07e161
Andrej Mitrovic authored
Showing with 49 additions and 2 deletions.
  1. +8 −2 src/func.c
  2. +41 −0 test/fail_compilation/diag9191.d
View
10 src/func.c
@@ -631,9 +631,15 @@ void FuncDeclaration::semantic(Scope *sc)
if (!doesoverride && isOverride())
{
- Dsymbol *s = cd->search_correct(ident);
+ Dsymbol *s = NULL;
+ for (size_t i = 0; i < cd->baseclasses->dim; i++)
+ {
+ s = (*cd->baseclasses)[i]->base->search_correct(ident);
+ if (s) break;
+ }
+
if (s)
- error("does not override any function, did you mean '%s'", s->toPrettyChars());
+ error("does not override any function, did you mean to override '%s'?", s->toPrettyChars());
else
error("does not override any function");
}
View
41 test/fail_compilation/diag9191.d
@@ -0,0 +1,41 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/diag9191.d(16): Error: function diag9191.C1.aaa does not override any function, did you mean to override 'diag9191.B1.aa'?
+fail_compilation/diag9191.d(21): Error: function diag9191.C2.aaa does not override any function, did you mean to override 'diag9191.I1.a'?
+fail_compilation/diag9191.d(31): Error: function diag9191.C3.foo does not override any function, did you mean to override 'diag9191.B2._foo'?
+fail_compilation/diag9191.d(36): Error: function diag9191.C4.toStringa does not override any function, did you mean to override 'object.Object.toString'?
+---
+*/
+
+interface I1 { void a(); }
+class B1 { void aa(); }
+
+class C1 : B1, I1
+{
+ override void aaa();
+}
+
+class C2 : I1
+{
+ override void aaa();
+}
+
+class B2
+{
+ void _foo(){}
+}
+
+class C3 : B2
+{
+ override void foo(){}
+}
+
+class C4
+{
+ override void toStringa(){}
+}
+
+void main()
+{
+}
Please sign in to comment.
Something went wrong with that request. Please try again.