Skip to content

Commit

Permalink
fix Issue 8390 - Refused array operation mutable[] += const[]
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jul 24, 2012
1 parent cae2114 commit 2bfc840
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/arrayop.c
Expand Up @@ -384,7 +384,7 @@ Expression *BinAssignExp::arrayOp(Scope *sc)

/* Check that the elements of e1 can be assigned to
*/
Type *tn = type->toBasetype()->nextOf();
Type *tn = e1->type->toBasetype()->nextOf();

if (tn && (!tn->isMutable() || !tn->isAssignable()))
{
Expand Down
13 changes: 12 additions & 1 deletion src/cast.c
Expand Up @@ -1888,6 +1888,7 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
//printf("typeMerge() %s op %s\n", (*pe1)->toChars(), (*pe2)->toChars());
//e->dump(0);

MATCH m;
Expression *e1 = *pe1;
Expression *e2 = *pe2;

Expand Down Expand Up @@ -2084,10 +2085,20 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
*/
goto Lx2;
}
else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2))
else if ((t1->ty == Tsarray || t1->ty == Tarray) &&
(m = t1->implicitConvTo(t2)) != MATCHnomatch)
{
if (t1->ty == Tsarray && e2->op == TOKarrayliteral)
goto Lt1;
if (m == MATCHconst &&
(e->op == TOKaddass || e->op == TOKminass || e->op == TOKmulass ||
e->op == TOKdivass || e->op == TOKmodass || e->op == TOKpowass ||
e->op == TOKandass || e->op == TOKorass || e->op == TOKxorass)
)
{ // Don't make the lvalue const
t = t2;
goto Lret;
}
goto Lt2;
}
else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1))
Expand Down
9 changes: 9 additions & 0 deletions test/runnable/arrayop.d
Expand Up @@ -542,6 +542,14 @@ void test6()

/************************************************************************/

void test8390() {
const int[] a = new int[5];
int[] b = new int[5];
b[] += a[];
}

/************************************************************************/

int main()
{
test1();
Expand All @@ -550,6 +558,7 @@ int main()
test4();
test5();
test6();
test8390();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 2bfc840

Please sign in to comment.