Skip to content

Commit

Permalink
Merge pull request #679 from yebblies/issue783
Browse files Browse the repository at this point in the history
Issue 783 - Cannot use an array w/ const or variable index as new[] size argument.
  • Loading branch information
WalterBright committed Mar 8, 2012
2 parents b7742f7 + a55ea85 commit 97b4410
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 @@ -4578,6 +4578,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 @@ -526,6 +526,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 @@ -3837,6 +3837,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 97b4410

Please sign in to comment.