Skip to content

Commit

Permalink
Issue 783 - Cannot use an array w/ const or variable index as new[] s…
Browse files Browse the repository at this point in the history
…ize argument.

The length is first parsed as an associate array type, so it needs to be reinterpreted as an expression.
  • Loading branch information
yebblies committed Feb 1, 2012
1 parent dc79160 commit a55ea85
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/mtype.c
Expand Up @@ -4531,6 +4531,22 @@ int TypeAArray::checkBoolean()
return TRUE;
}

Expression *TypeAArray::toExpression()
{
Expression *e = next->toExpression();
if (e)
{
Expression *ei = index->toExpression();
if (ei)
{
Expressions *arguments = new Expressions();
arguments->push(ei);
return new ArrayExp(loc, e, arguments);
}
}
return NULL;
}

int TypeAArray::hasPointers()
{
return TRUE;
Expand Down
1 change: 1 addition & 0 deletions src/mtype.h
Expand Up @@ -525,6 +525,7 @@ struct TypeAArray : TypeArray
int isZeroInit(Loc loc);
int checkBoolean();
TypeInfoDeclaration *getTypeInfoDeclaration();
Expression *toExpression();
int hasPointers();
TypeTuple *toArgTypes();
MATCH implicitConvTo(Type *to);
Expand Down
9 changes: 9 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -3644,6 +3644,15 @@ ref const(Foo6529) func6529(const(Foo6529)[] arr){ return arr[0]; }

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

void test783()
{
const arr = [ 1,2,3 ];
const i = 2;
auto jhk = new int[arr[i]]; // "need size of rightmost array, not type arr[i]"
}

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

template X157(alias x)
{
alias x X157;
Expand Down

0 comments on commit a55ea85

Please sign in to comment.