From 0c46d6921050907fe413244cbe71cfa7b93135a2 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Mon, 20 Feb 2012 23:09:42 -0800 Subject: [PATCH] fix Issue 5554 - [qtd] Covariance detection failure --- src/func.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/func.c b/src/func.c index 9d4bee6ec64f..8a88ece1279f 100644 --- a/src/func.c +++ b/src/func.c @@ -461,13 +461,21 @@ void FuncDeclaration::semantic(Scope *sc) return; default: - { FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl.data[vi]; + { FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl.tdata()[vi]; Type *ti = NULL; /* Remember which functions this overrides */ foverrides.push(fdv); +#if DMDV2 + /* Should we really require 'override' when implementing + * an interface function? + */ + //if (!isOverride()) + //warning(loc, "overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars()); +#endif + if (fdv->tintro) ti = fdv->tintro; else if (!type->equals(fdv->type)) @@ -492,10 +500,15 @@ void FuncDeclaration::semantic(Scope *sc) } if (ti) { - if (tintro && !tintro->equals(ti)) + if (tintro) + { + 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; } goto L2; @@ -569,7 +582,7 @@ void FuncDeclaration::semantic(Scope *sc) if (f->varargs) { Lmainerr: - error("parameters must be main() or main(char[][] args)"); + error("parameters must be main() or main(string[] args)"); } }