www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9570] New: Wrong foreach index implicit conversion error

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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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: -------
Feb 22 2013