Skip to content

Commit

Permalink
Merge pull request #2236 from 9rnsr/fix10433
Browse files Browse the repository at this point in the history
Issue 10433 - Array sum operation in function template
  • Loading branch information
yebblies committed Jun 21, 2013
2 parents 38dc0e4 + d964f31 commit 1adbc5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cast.c
Expand Up @@ -1054,6 +1054,7 @@ MATCH SliceExp::implicitConvTo(Type *t)

/**************************************
* Do an explicit cast.
* Assume that the 'this' expression does not have any indirections.
*/

Expression *Expression::castTo(Scope *sc, Type *t)
Expand Down Expand Up @@ -1857,6 +1858,14 @@ Expression *SliceExp::castTo(Scope *sc, Type *t)
e = copy();
e->type = t;
}
else if (typeb->ty == Tarray && tb->ty == Tarray &&
typeb->nextOf()->constConv(tb->nextOf()) == MATCHconst)
{
// immutable(T)[] to const(T)[]
// T [] to const(T)[]
e = copy();
e->type = t;
}
else
{
e = Expression::castTo(sc, t);
Expand Down
16 changes: 16 additions & 0 deletions test/runnable/arrayop.d
Expand Up @@ -648,6 +648,21 @@ void test9656()
}
}

/************************************************************************/
// 10433

void test10433()
{
void foo(T)(in int[] v1, in T v2)
{
int[2] r;
r[] = v1[] + v2[];
}

immutable int[] v = [10, 20];
foo(v, v);
}

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

int main()
Expand All @@ -661,6 +676,7 @@ int main()
test8390();
test8651();
test9656();
test10433();

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

0 comments on commit 1adbc5f

Please sign in to comment.