diff --git a/src/opover.c b/src/opover.c index 6adcd6293bce..4c9c5b2d2cd3 100644 --- a/src/opover.c +++ b/src/opover.c @@ -1472,12 +1472,12 @@ bool inferAggregate(ForeachStatement *fes, Scope *sc, Dsymbol *&sapply) { sapply = search_function(ad, idapply); if (sapply) - { // opApply aggregate + { + // opApply aggregate break; } - Dsymbol *s = search_function(ad, Id::slice); - if (s) + if (fes->aggr->op != TOKtype) { Expression *rinit = new ArrayExp(aggr->loc, aggr); rinit = rinit->trySemantic(sc); diff --git a/test/runnable/opover2.d b/test/runnable/opover2.d index 6824ee7e4731..ebde24d38bca 100644 --- a/test/runnable/opover2.d +++ b/test/runnable/opover2.d @@ -1979,6 +1979,36 @@ void test14624() } } +/**************************************/ +// 14625 + +void test14625() +{ + struct R + { + @property bool empty() { return true; } + @property int front() { return 0; } + void popFront() {} + } + + struct C1 + { + R opIndex() { return R(); } + R opSlice() { assert(0); } + } + C1 c1; + foreach (e; c1) {} // OK <- asserts in opSlice() + foreach (e; c1[]) {} // OK, opIndex() + + struct C2 + { + R opIndex() { return R(); } + } + C2 c2; + foreach (e; c2) {} // OK <- rejected + foreach (e; c2[]) {} // OK, opIndex() +} + /**************************************/ int main() @@ -2025,6 +2055,7 @@ int main() test20c(); test20d(); test14624(); + test14625(); printf("Success\n"); return 0;