Skip to content

Commit

Permalink
Merge pull request #1233 from dawgfoto/fixupBug7097
Browse files Browse the repository at this point in the history
fixup of pull #577
  • Loading branch information
9rnsr committed Oct 29, 2012
2 parents a88decb + 462cb8b commit 2769221
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/dsymbol.c
Expand Up @@ -1369,22 +1369,32 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
return NULL;
s = s->toAlias();

Expression *e;
TemplateDeclaration *td;
// Check for multi-dimensional opDollar(dim)(). Only for ArrayExp.
if (exp->op == TOKarray && (td = s->isTemplateDeclaration()))
Expression *e = NULL;
// Check for multi-dimensional opDollar(dim) template.
if (TemplateDeclaration *td = s->isTemplateDeclaration())
{
ArrayExp *ae = (ArrayExp *)exp;
// Instantiate opDollar!(dim) with the index as a template argument
dinteger_t dim;
if (exp->op == TOKarray)
{
dim = ((ArrayExp *)exp)->currentDimension;
e = ((ArrayExp *)exp)->e1;
}
else if (exp->op == TOKslice)
{
dim = 0; // slices are currently always one-dimensional
e = ((SliceExp *)exp)->e1;
}
assert(e);

Objects *tdargs = new Objects();
Expression *dim = new IntegerExp(0, ae->currentDimension, Type::tsize_t);
dim = dim->semantic(sc);
tdargs->push(dim);
Expression *edim = new IntegerExp(0, dim, Type::tsize_t);
edim = edim->semantic(sc);
tdargs->push(edim);

//TemplateInstance *ti = new TemplateInstance(loc, td, tdargs);
//ti->semantic(sc);

e = new DotTemplateInstanceExp(loc, ae->e1, td->ident, tdargs);
e = new DotTemplateInstanceExp(loc, e, td->ident, tdargs);
}
else
{ /* opDollar exists, but it's not a template.
Expand Down
22 changes: 22 additions & 0 deletions test/runnable/opover2.d
Expand Up @@ -903,6 +903,27 @@ void test18()

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

void test19()
{
static struct Foo
{
int[] opSlice(int a, int b)
{
return [a, b];
}

int opDollar(int dim)()
{
return dim;
}
}

Foo foo;
assert(foo[0 .. $] == [0, 0]);
}

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

int main()
{
test1();
Expand All @@ -926,6 +947,7 @@ int main()
test7641();
test8434();
test18();
test19();

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

0 comments on commit 2769221

Please sign in to comment.