From 462cb8b0f3287b12c253bd7f3e6fd93b879bdc25 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Mon, 29 Oct 2012 05:12:28 +0100 Subject: [PATCH] fixup of pull #577 - fix usage of templated opDollar with one-dimensional opSlice --- src/dsymbol.c | 30 ++++++++++++++++++++---------- test/runnable/opover2.d | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/dsymbol.c b/src/dsymbol.c index 7ca41f0f1714..faf89f488391 100644 --- a/src/dsymbol.c +++ b/src/dsymbol.c @@ -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. diff --git a/test/runnable/opover2.d b/test/runnable/opover2.d index 446dc0086233..753dea3c30c2 100644 --- a/test/runnable/opover2.d +++ b/test/runnable/opover2.d @@ -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(); @@ -926,6 +947,7 @@ int main() test7641(); test8434(); test18(); + test19(); printf("Success\n"); return 0;