Skip to content

Commit

Permalink
fix Issue 11627 - [CTFE] cannot cast dchar to char at compile time on…
Browse files Browse the repository at this point in the history
… AA assignment
  • Loading branch information
9rnsr committed Nov 30, 2013
1 parent 9a7ebe8 commit 7832449
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -14006,8 +14006,7 @@ Expression *BinExp::reorderSettingAAElem(Scope *sc)
/* Check recursive conversion */
VarDeclaration *var;
bool isrefvar = (e2->op == TOKvar &&
(var = ((VarExp *)e2)->var->isVarDeclaration()) != NULL &&
(var->storage_class & STCref));
(var = ((VarExp *)e2)->var->isVarDeclaration()) != NULL);
if (isrefvar)
return this;

Expand Down Expand Up @@ -14045,7 +14044,9 @@ Expression *BinExp::reorderSettingAAElem(Scope *sc)
{
Identifier *id = Lexer::uniqueId("__aaval");
VarDeclaration *vd = new VarDeclaration(loc, this->e2->type, id, new ExpInitializer(this->e2->loc, this->e2));
vd->storage_class |= STCref | STCforeach | (this->e2->isLvalue() ? 0 : STCtemp);
vd->storage_class |= STCtemp;
if (this->e2->isLvalue())
vd->storage_class |= STCref | STCforeach;
Expression *de = new DeclarationExp(this->e2->loc, vd);

ec = ec ? new CommaExp(loc, ec, de) : de;
Expand Down
4 changes: 2 additions & 2 deletions src/interpret.c
Original file line number Diff line number Diff line change
Expand Up @@ -3267,8 +3267,8 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, CtfeGoal goal, fp_
if (op == TOKconstruct && this->e1->op==TOKvar
&& ((VarExp*)this->e1)->var->storage_class & STCref)
{
wantRef = true;
wantLvalueRef = true;
wantRef = true;
wantLvalueRef = true;
}

if (fp)
Expand Down
16 changes: 16 additions & 0 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -6080,3 +6080,19 @@ static assert(()

return 1;
}());

/**************************************************
11627 - cast dchar to char at compile time on AA assignment
**************************************************/

bool test11627()
{
char[ubyte] toCharTmp;
dchar letter = 'A';

//char c = cast(char)letter; // OK
toCharTmp[0] = cast(char)letter; // NG

return true;
}
static assert(test11627());

0 comments on commit 7832449

Please sign in to comment.