From ca61268e644f937e60bac31f0de4c56a1641738d Mon Sep 17 00:00:00 2001 From: Daniel Murphy Date: Mon, 20 Feb 2012 23:24:49 +1100 Subject: [PATCH] Fix Issue 5554 - [qtd] Covariance detection failure The functions match is A is a base class of B, _or_ if B is a base class of A. --- src/func.c | 9 +++++++-- test/runnable/xtest46.d | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/func.c b/src/func.c index 40bb05fecd82..95f78f84fdd8 100644 --- a/src/func.c +++ b/src/func.c @@ -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; } diff --git a/test/runnable/xtest46.d b/test/runnable/xtest46.d index 4c986c4d0a0b..3522f95af813 100644 --- a/test/runnable/xtest46.d +++ b/test/runnable/xtest46.d @@ -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 @@ -4730,6 +4750,7 @@ int main() test85(); test86(); test87(); + test5554(); test88(); test7545(); test89();