Skip to content

Commit

Permalink
fix Issue 15913 - cannot initialize immutable fixed size array withou…
Browse files Browse the repository at this point in the history
…t similar const-code
  • Loading branch information
9rnsr committed Apr 23, 2016
1 parent 84d9f10 commit 260d3de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/arrayop.d
Expand Up @@ -64,7 +64,7 @@ extern (C++) FuncDeclaration buildArrayOp(Identifier ident, BinExp exp, Scope* s

/* Construct the function
*/
auto ftype = new TypeFunction(fparams, exp.type, 0, LINKc, stc);
auto ftype = new TypeFunction(fparams, exp.e1.type, 0, LINKc, stc);
//printf("fd: %s %s\n", ident.toChars(), ftype.toChars());
//printf("fbody: %s\n", fbody.toChars());
auto fd = new FuncDeclaration(Loc(), Loc(), ident, STCundefined, ftype);
Expand Down
6 changes: 6 additions & 0 deletions test/runnable/arrayop.d
Expand Up @@ -659,6 +659,12 @@ void test10282()
const int[3] a3 = a1[] * 3; // OK <- Error
const int[3] a4 = [1, 3, 6] * 3; // OK <- Error
immutable int[3] a5 = [1, 3, 6] * 3; // OK <- Error

assert(a1[0] == 1 && a1[1] == 3 && a1[2] == 6);
assert(a2[0] == 3 && a2[1] == 9 && a2[2] == 18);
assert(a3[0] == 3 && a3[1] == 9 && a3[2] == 18);
assert(a4[0] == 3 && a4[1] == 9 && a4[2] == 18);
assert(a5[0] == 3 && a5[1] == 9 && a5[2] == 18);
}

/************************************************************************/
Expand Down
7 changes: 7 additions & 0 deletions test/runnable/test15913.d
@@ -0,0 +1,7 @@
void main()//test10282()
{
//const int[3] a4 = [1, 3, 6] * 3;
immutable int[3] a5 = [1, 3, 6] * 3;

assert(a5[0] == 3 && a5[1] == 9 && a5[2] == 18);
}

0 comments on commit 260d3de

Please sign in to comment.