[Issue 9570] Wrong foreach index implicit conversion error

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed May 21 13:34:10 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=9570

--- Comment #6 from bearophile_hugs at eml.cc ---
(In reply to Lionello Lunesu from comment #5)

> No, the key must be declared const or immutable. Otherwise we need flow
> analysis to ensure the key doesn't get mutated in the scope.

I don't understand what's the problem. What kind of bad things do happen if the
key gets mutated in the scope?

void main() {
    ubyte[256] data;
    foreach (ubyte i, ref x; data) {
        x = i;
        i++; // overflow here
    }
}

--


More information about the Digitalmars-d-bugs mailing list