Comment #0 by qs.il.paperinik — 2020-06-06T18:17:11Z
A quick and easy way to trigger the OutOfMemoryError
struct SimpleRange
{
this(int front) { this.front = front; }
bool empty = false;
int front;
void popFront() { }
}
void main()
{
static foreach (x; SimpleRange(1)) { }
}
While it is somewhat obvious that it cannot work, the compiler tells me, there's a bug in the compiler (
> ERROR: This is a compiler bug.
> Please report it via https://issues.dlang.org/enter_bug.cgi
). And in some way there is. The compiler cannot know that the range is infinite, but it can just abort at some point.
Comment #1 by qs.il.paperinik — 2023-09-12T13:35:24Z
I’d suggest DMD abort when a `static foreach` surpasses 2^16−1 (65,535) iterations; also add a compiler switch (suggestion: `-static-foreach-depth=<number>`) to change the aforementioned default for the rare cases it’s needed. Alternatively, a `pragma` could work well, too.
Comment #2 by robert.schadek — 2024-12-13T19:09:03Z