Browse files

Issue 4511 - Covariance problem

When returning an expression from an overriding function covariant, ensure the expression is castable to the derived type as well as the base type.
  • Loading branch information...
1 parent 4306f78 commit 13bd317bc52bce7eb697e2c3c6a6ce09f2f0c5cc @yebblies committed Jun 17, 2011
Showing with 2 additions and 0 deletions.
  1. +2 −0 src/statement.c
View
2 src/statement.c
@@ -3626,6 +3626,8 @@ Statement *ReturnStatement::semantic(Scope *sc)
exp = exp->castTo(sc, exp->type->invariantOf());
}
+ if (fd->tintro)
+ exp = exp->implicitCastTo(sc, fd->type->nextOf());
exp = exp->implicitCastTo(sc, tret);
if (!((TypeFunction *)fd->type)->isref)
exp = exp->optimize(WANTvalue);

0 comments on commit 13bd317

Please sign in to comment.