[Issue 9570] Wrong foreach index implicit conversion error

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


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

--- Comment #8 from bearophile_hugs at eml.cc ---
(In reply to yebblies from comment #7)

> void main() {
>     ubyte[256] data;
>     foreach (ubyte i, ref x; data) {
>         i = 99999;
>         x = i; // information lost
>     }
> }

This code should give (as it currently gives):
temp.d(4,13): Error: cannot implicitly convert expression (99999) of type int
to ubyte

Here i scan a ubyte range 0 .. 255, so tagging it as ubyte is OK. I think it's
irrelevant that later I try to overflow the contents of i.

Even this is OK for D, despite 'i' gets overflowed:

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


So I still don't see the problem.

--


More information about the Digitalmars-d-bugs mailing list