Skip to content

Commit

Permalink
fix Issue 14851 - Cannot assign array operation result to static arra…
Browse files Browse the repository at this point in the history
…y variable
  • Loading branch information
9rnsr committed Jul 31, 2015
1 parent d69289b commit 2029e52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/expression.c
Expand Up @@ -11572,6 +11572,20 @@ Expression *AssignExp::semantic(Scope *sc)
if (e1x->checkPostblit(sc, t1))
return new ErrorExp();
}

// e2 matches to t1 because of the implicit length match, so
if (isUnaArrayOp(e2x->op) || isBinArrayOp(e2x->op))
{
// convert e1 to e1[]
// e.g. e1[] = a[] + b[];
e1x = new SliceExp(e1x->loc, e1x, NULL, NULL);
e1x = e1x->semantic(sc);
}
else
{
// convert e2 to t1 later
// e.g. e1 = [1, 2, 3];
}
}
else
{
Expand Down
15 changes: 15 additions & 0 deletions test/runnable/arrayop.d
Expand Up @@ -883,6 +883,20 @@ void test14649()
assert(r == [('a'+'d'), ('b'+'e'), ('c'+'f')]);
}

/************************************************************************/
// 14851

void test14851()
{
int[8] a, b, c;

c = a[] | b[]; // OK <- NG from 2.068.0-b2
c = a[] ^ b[]; // OK <- NG from 2.068.0-b2

c[] = a[] | b[]; // OK
c[] = a[] ^ b[]; // OK
}

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

int main()
Expand All @@ -905,6 +919,7 @@ int main()
test12780();
test13497();
test14649();
test14851();

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

0 comments on commit 2029e52

Please sign in to comment.