Skip to content

Commit

Permalink
Merge pull request #1436 from AndrejMitrovic/Fix9191
Browse files Browse the repository at this point in the history
Issue 9191 - Wrong diagnostic on failing override
  • Loading branch information
Don Clugston committed Jan 7, 2013
2 parents e818024 + 5bcba1f commit 870bc86
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
41 changes: 41 additions & 0 deletions test/fail_compilation/diag9191.d
Original file line number Diff line number Diff line change
@@ -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()
{
}

0 comments on commit 870bc86

Please sign in to comment.