www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10594] New: Shaping the value range for immutable variables

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

           Summary: Shaping the value range for immutable variables
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



(This is an improvement for Issue 10018 , but it's sufficiently different, so I
have opened a new issue.)

Currently this fails:

void main(in string[] args) {
    immutable ushort x = args.length % 5;
    immutable ubyte y = x;
}


dmd 2.064alpha gives:

temp.d(3): Error: cannot implicitly convert expression (x) of type
immutable(ushort) to immutable(ubyte)


Issue 10018 asks to propagate the range of immutable values, allowing that code
to compile with no errors.

- - - - - - - - - - -

This is an improvement of that idea:


void main(in string[] args) {
    immutable size_t x = args.length;
    assert(x < 256);
    immutable ubyte y = x;
}


x is an immutable full-range size_t. But the assert should change the range of
x, allowing the successive assignment of y to be accepted.

- - - - - - - - - - -

Another possible idea is to allow code like:


void main(in string[] args) {
    immutable size_t x = args.length;
    if (x < 256) {
        immutable ubyte y = x;
    }
}

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