Skip to content

Commit

Permalink
fix Issue 12604 - No "mismatched array lengths" error with narrowing …
Browse files Browse the repository at this point in the history
…conversions
  • Loading branch information
9rnsr committed Apr 21, 2014
1 parent 8903f3f commit a833827
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/expression.c
Expand Up @@ -11168,6 +11168,18 @@ Expression *AssignExp::semantic(Scope *sc)
}
else
{
if (e2x->op == TOKarrayliteral)
{
ArrayLiteralExp *ale = (ArrayLiteralExp *)e2x;
uinteger_t dim1 = ((TypeSArray *)t1)->dim->toInteger();
uinteger_t dim2 = ale->elements ? ale->elements->dim : 0;
if (e2x->implicitConvTo(t1->nextOf()->sarrayOf(dim2)))
{
error("mismatched array lengths, %d and %d", (int)dim1, (int)dim2);
return new ErrorExp();
}
}

// May be block or element-wise assignment, so
// convert e1 to e1[]
if (op != TOKassign)
Expand Down
22 changes: 22 additions & 0 deletions test/fail_compilation/fail12604.d
@@ -0,0 +1,22 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail12604.d(14): Error: mismatched array lengths, 1 and 3
fail_compilation/fail12604.d(15): Error: mismatched array lengths, 1 and 3
fail_compilation/fail12604.d(17): Error: mismatched array lengths, 1 and 3
fail_compilation/fail12604.d(18): Error: mismatched array lengths, 1 and 3
fail_compilation/fail12604.d(20): Error: cannot implicitly convert expression ([65536]) of type int[] to short[]
fail_compilation/fail12604.d(21): Error: cannot implicitly convert expression ([65536, 2, 3]) of type int[] to short[]
---
*/
void main()
{
int[1] a1 = [1,2,3];
short[1] a2 = [1,2,3];

int[1] b1; b1 = [1,2,3];
short[1] b2; b2 = [1,2,3];

short[1] c = [65536];
short[1] d = [65536,2,3];
}

0 comments on commit a833827

Please sign in to comment.