| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/fail118.d(45): Error: invalid `foreach` aggregate `Iter` of type `Iter` |
| 5 |
fail_compilation/fail118.d(45): `foreach` works with input ranges (implementing `front` and `popFront`), aggregates implementing `opApply`, or the result of an aggregate's `.tupleof` property |
| 6 |
fail_compilation/fail118.d(45): https://dlang.org/phobos/std_range_primitives.html#isInputRange |
| 7 |
fail_compilation/fail118.d(46): Error: invalid `foreach` aggregate `Iter` of type `Iter` |
| 8 |
fail_compilation/fail118.d(46): `foreach` works with input ranges (implementing `front` and `popFront`), aggregates implementing `opApply`, or the result of an aggregate's `.tupleof` property |
| 9 |
fail_compilation/fail118.d(46): https://dlang.org/phobos/std_range_primitives.html#isInputRange |
| 10 |
fail_compilation/fail118.d(49): Error: invalid `foreach` aggregate `s` of type `S*` |
| 11 |
fail_compilation/fail118.d(51): Error: undefined identifier `unknown` |
| 12 |
fail_compilation/fail118.d(39): Error: undefined identifier `doesNotExist` |
| 13 |
fail_compilation/fail118.d(53): Error: template instance `fail118.error!()` error instantiating |
| 14 |
fail_compilation/fail118.d(53): Error: invalid `foreach` aggregate `error()` of type `void` |
| 15 |
--- |
| 16 |
*/ |
| 17 |
|
| 18 |
// https://issues.dlang.org/show_bug.cgi?id=441 |
| 19 |
// Crash on foreach of mixed-in aggregate. |
| 20 |
template opHackedApply() |
| 21 |
{ |
| 22 |
struct Iter |
| 23 |
{ |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
class Foo |
| 28 |
{ |
| 29 |
mixin opHackedApply!() oldIterMix; |
| 30 |
} |
| 31 |
|
| 32 |
struct S |
| 33 |
{ |
| 34 |
int opApply(scope int delegate(const int) dg); |
| 35 |
} |
| 36 |
|
| 37 |
auto error()() |
| 38 |
{ |
| 39 |
doesNotExist(); |
| 40 |
} |
| 41 |
|
| 42 |
void main() |
| 43 |
{ |
| 44 |
Foo f = new Foo; |
| 45 |
foreach (int i; f.oldIterMix.Iter) {} |
| 46 |
foreach ( i; f.oldIterMix.Iter) {} |
| 47 |
|
| 48 |
S* s; |
| 49 |
foreach (const i; s) {} |
| 50 |
|
| 51 |
foreach(const i; unknown) {} |
| 52 |
|
| 53 |
foreach (const i; error()) {} |
| 54 |
} |