[Issue 9570] New: Wrong foreach index implicit conversion error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 22 09:38:53 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9570

           Summary: Wrong foreach index implicit conversion error
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic, rejects-valid
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-02-22 09:38:53 PST ---
void main() {
    ubyte[256] data;
    foreach (const i, x; data)
        data[i] = i;
}


DMD 2.063alpha gives:

test.d(4): Error: cannot implicitly convert expression (i) of type const(uint)
to ubyte


Here "data" is a fixed-size array, with length known statically to be 256, so
the index "i" of the foreach is statically known to be in [0,256[, that is the
range of a ubyte. So the conversion error given by the compiler is wrong.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list