Skip to content

Commit

Permalink
Merge pull request #1378 from 9rnsr/fix5204
Browse files Browse the repository at this point in the history
Issue 5204 - Inherited out contract requires lvalue result?
  • Loading branch information
MartinNowak committed Dec 15, 2012
2 parents 4902f8a + 6086205 commit 0002539
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/func.c
Expand Up @@ -1993,7 +1993,25 @@ Statement *FuncDeclaration::mergeFensure(Statement *sf)
// Make the call: __ensure(result)
Expression *eresult = NULL;
if (outId)
{
eresult = new IdentifierExp(loc, outId);

Type *t1 = fdv->type->nextOf()->toBasetype();
Type *t2 = this->type->nextOf()->toBasetype();
int offset;
if (t1->isBaseOf(t2, &offset) && offset != 0)
{
/* Making temporary reference variable is necessary
* to match offset difference in covariant return.
* See bugzilla 5204.
*/
ExpInitializer *ei = new ExpInitializer(0, eresult);
VarDeclaration *v = new VarDeclaration(0, t1, Lexer::uniqueId("__covres"), ei);
DeclarationExp *de = new DeclarationExp(0, v);
VarExp *ve = new VarExp(0, v);
eresult = new CommaExp(0, de, ve);
}
}
Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdensure, 0), eresult);
Statement *s2 = new ExpStatement(loc, e);

Expand Down
13 changes: 13 additions & 0 deletions test/runnable/testcontracts.d
Expand Up @@ -343,6 +343,19 @@ class C5039 {
}
}

/*******************************************/
// 5204

interface IFoo5204
{
IFoo5204 bar()
out {}
}
class Foo5204 : IFoo5204
{
Foo5204 bar() { return null; }
}

/*******************************************/
// 7218

Expand Down

0 comments on commit 0002539

Please sign in to comment.