Skip to content

Commit

Permalink
Merge pull request #746 from yebblies/issue5554
Browse files Browse the repository at this point in the history
Issue 5554 - [qtd] Covariance detection failure
  • Loading branch information
WalterBright committed Feb 21, 2012
2 parents 907c94d + ca61268 commit 027fdbc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/func.c
Expand Up @@ -609,9 +609,14 @@ void FuncDeclaration::semantic(Scope *sc)
}
if (ti)
{
if (tintro && !tintro->equals(ti))
if (tintro)
{
error("incompatible covariant types %s and %s", tintro->toChars(), ti->toChars());
if (!tintro->nextOf()->equals(ti->nextOf()) &&
!tintro->nextOf()->isBaseOf(ti->nextOf(), NULL) &&
!ti->nextOf()->isBaseOf(tintro->nextOf(), NULL))
{
error("incompatible covariant types %s and %s", tintro->toChars(), ti->toChars());
}
}
tintro = ti;
}
Expand Down
21 changes: 21 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -3383,6 +3383,26 @@ ref func2521_7() {
return val;
}

/***************************************************/

void test5554()
{
class MA { }
class MB : MA { }
class MC : MB { }

class A { abstract MA foo(); }
interface I { MB foo(); }
class B : A
{
MC foo() { return null; }
}
class C : B, I
{
override MC foo() { return null; }
}
}

/***************************************************/
// 5962

Expand Down Expand Up @@ -4730,6 +4750,7 @@ int main()
test85();
test86();
test87();
test5554();
test88();
test7545();
test89();
Expand Down

0 comments on commit 027fdbc

Please sign in to comment.