Skip to content

Commit

Permalink
7419 [2.058/CTFE] Constructor of struct is overwritten with -inline
Browse files Browse the repository at this point in the history
The logic for ref variables was incorrect. Stripping out _all_ of the funky
foreach code fixes it.
Fixes bug 7419.
  • Loading branch information
Don Clugston committed Feb 2, 2012
1 parent 960f6fd commit 127d011
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/interpret.c
Expand Up @@ -3448,6 +3448,13 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, CtfeGoal goal, fp_
{
wantRef = true;
}
// If it is a construction of a ref variable, it is a ref assignment
if (op == TOKconstruct && this->e1->op==TOKvar
&& ((VarExp*)this->e1)->var->storage_class & STCref)
{
wantRef = true;
}

if (fp)
{
while (e1->op == TOKcast)
Expand Down Expand Up @@ -3714,20 +3721,6 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, CtfeGoal goal, fp_
return EXP_CANT_INTERPRET;
}

// This happens inside compiler-generated foreach statements.
if (op==TOKconstruct && this->e1->op==TOKvar &&
this->e2->op == TOKindex
&& ((VarExp*)this->e1)->var->storage_class & STCref)
{
VarDeclaration *v = ((VarExp *)e1)->var->isVarDeclaration();
#if (LOGASSIGN)
printf("FOREACH ASSIGN %s=%s\n", v->toChars(), e2->toChars());
#endif
v->setValueNull();
v->setValue(e2);
return e2;
}

e1 = resolveReferences(e1, istate->localThis);

// Unless we have a simple var assignment, we're
Expand Down Expand Up @@ -4784,8 +4777,7 @@ Expression *CallExp::interpret(InterState *istate, CtfeGoal goal)
{
if (e->op == TOKslice)
e= resolveSlice(e);
e = expType(type, e);
e = copyLiteral(e);
e = paintTypeOntoLiteral(type, copyLiteral(e));
}
return e;
}
Expand Down
19 changes: 19 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -3941,6 +3941,25 @@ bool test7158() {
}
static assert(test7158());

/**************************************************
7419
**************************************************/

struct X7419 {
double x;
this(double x) {
this.x = x;
}
}

void bug7419() {
enum x = {
auto p = X7419(3);
return p.x;
}();
static assert(x == 3);
}

/**************************************************
7162 and 4711
**************************************************/
Expand Down

0 comments on commit 127d011

Please sign in to comment.